Pages - ZingPHP/Zing GitHub Wiki
Pages are groupings of code, or code that does similar things. They are used to build pages, and they should extend the Zing framework in order to use the framework. They should also be placed within your website, for example: websites/Pages/Home.php
.
There are multiple ways to access a page, and they look like this:
- Default
-
http://example.com/
- Defaults toPages/Home.php>>Home::main()
-
http://example.com/settings
- Goes toPages/Settings.php>>Settings::main()
-
http://example.com/settings/email
- Goes toPages/Settings.php>>Settings::email()
-
- Routing
- Inside the config file, you can set your own paths. See Page Routing for more information.
The following snippet is the minimum a page should have, main()
is not required but it is suggested.
<?php
// Create a default landing page for when someone hits http://example.com/
class Home extends Zing{
public function main(){
// This is the default page that runs
// if no other page is specified
}
}
Pages can use modules that have been defined in the Zing core, for example:
<?php
class Home extends Zing{
public function main(){
echo '<form method="post" action="./home/email">';
echo '<p><input type="email" placeholder="email" /></p>';
echo '<p><input type="submit" value="Show My Email" /></p>';
echo '</form>';
}
public function email(){
$email = $this->input->post("email");
if($this->input->isEmail($email)){
echo "You entered: <b>$email</b>";
}else{
echo "You entered an invalid email";
}
}
}
Any ajax request that you would like to do should pipe through the ajax path. Then in your page, you would then append Ajax
to the method name, take this URL:
http://example.com/ajax/home/email
It would then look something like this in your page class:
<?php
class Home extends Zing{
public function emailAjax(){
echo json_encode("[email protected]");
}
}
Note: You can not use templates in your AJAX requests