1. Go to this page and download the library: Download dariushha/zinux library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
# PROJECT-ROOT/application/appBoostrap.php
namespace application;
class appBoostrap extends \zinux\kernel\application\applicationBootstrap
{
public function PRE_CHECK(\zinux\kernel\routing\request &$request)
{
/**
* this is a pre-strap function use this on pre-bootstrap opt.
* @param \zinux\kernel\routing\request $request
*/
}
public function post_FOO(\zinux\kernel\routing\request $request)
{
/**
* this is a post-strap function use this on post-bootstrap opt.
* @param \zinux\kernel\routing\request $request
*/
}
}
namespace modules\defaultModule;
class defaultBootstrap
{
# Predispatch method #1
public function PRE_echo(\zinux\kernel\routing\request $request)
{
echo "I am predispatch #1<br />";
echo "<div style='color:darkred'>";
echo "<br />You have requested:";
echo "<br />Module : ".$request->module->full_name;
echo "<br />Controller : ".$request->controller->full_name;
echo "<br />Action : ".$request->action->full_name;
echo "<br />View : ".$request->view->full_name;
echo "</div>";
}
# Predispatch method #2
public function PRE_echo1(\zinux\kernel\routing\request $request)
{
echo "I am predispatch #2<br />";
}
# Postdispatch method #1
public function POST_echo(\zinux\kernel\routing\request $request)
{
echo "I am postdispatch #1<br />";
}
# Postdispatch method #2
public function POST_echo1(\zinux\kernel\routing\request $request)
{
echo "I am postdispatch #2<br />";
}
# This function would never gets called beacause
# It does not have 'pre_' OR 'post_' naming prefix
public function FooFunc()
{
echo __METHOD__." will never get invoked...";
}
}
# in our controller we path varibales like this
$this->view->passed_from_controller = $some_value;
# in our view we access variable like this
echo $this->passed_from_controller;
# in our controller OR view we path varibales like this
$this->layout->passed_from_controller_or_view = $some_value;
# in our layout we access variable like this
echo $this->passed_from_controller_or_view;
# Assume that we have Layout named 'LoginView'(case-insensitve) under current module/controller
# following code will change current view to 'LoginView'
$this->view->SetView("Login");
# disable view(i.e loading no view only view)
$this->view->SuppressView();
# Assume that we have Layout named 'CoolLayout'(case-insensitve) under current module
# following code will change current layout to 'CoolLayout'
$this->layout->SetLayout("COOL");
# disable any layouting(i.e loading no layout only view)
$this->layout->SuppressLayout();
# Assume that we have Helper file named 'fOoModel.php'(case-insensitve) under current module
# loades fOoModel.php which is under current module ($this->request->module)
# the exact use of this code is valid in
# {Contoller}
# {Model}
# {View}
# {Layout}
new \zinux\kernel\mvc\helper("foo", $this->request->module);
# now we can use functions in 'fOoHelper.php' file
some_Function_In_fOo('Hello, world')
# this controller locates at
# PROJECT-ROOT/Modules/SomeModule/Controllers/FooController.php
namespace \Modules\SomeController\Controllers;
/**
*
* Remember that files pathes are not case sensitive
*
*/
class FooController extends \zinux\kernel\controller\baseController
{
public function Initiate()
{
/**
* Do your init stuffs here
* This method will get called
* just before invoking actions
*/
}
/**
* Url map to this controller :
*
* /some/foo/some/var?or=GET
*
* |OR|
*
* /some/foo/index/some/var?or=GET
*/
public function IndexAction()
{
# lets see that is the request's params are
\zinux\kernel\utilities\debug::_var($this->request->params);
/**
* output:
*
* Array
* (
* [some] => var
* [or] => GET
* )
*
*/
}
/**
* Url map to this controller :
*
* /some/foo/feed
*/
public function FeedAction()
{
# let assume that we have some data
$data = some_data_generator();
# if the 'json' format is requested
# i.e the uri is :
# /some/foo/feed.json
if($this->request->type == "json")
{
# we dont want any view or layout here
$this->view->SuppressView();
# print out json format of data
echo json_encode($data);
return;
}
# or if the 'raw' format is requested
# i.e the uri is :
# /some/foo/feed.json
elseif($this->request->type == "raw")
{
# we dont want any view or layout here
$this->view->SuppressView();
# print out the raw format of $data
\zinux\kernel\utilities\debug::_var($data);
return;
}
# if was not a json request
# pass data to view
$this->view->some_data = $data;
# set layout to feedLayout
$this->layout->SetLayout("feed");
}
/**
* Url map to this controller :
*
* /some/foo/modeluse
*/
public function ModelUseAction()
{
/**
*
* In this action are trying to show
* how to use model and helper
*
*/
# Assume that we have a model in following path
# PROJECT-ROOT/Modules/SomeModule/Models/Xoxo.php
$o = \modules\SomeModule\Models\Xoxo();
# fetch some data from xoxo class
$this->view->new_data = $o->get_some_data();
# test data validation
if($this->view->new_data)
{
# Assume that we have a helper in following path
# PROJECT-ROOT/Modules/SomeModules/Views/Helper/A_helper.php
new \zinux\kernel\mvc\helper("a_helper", $this->request->module);
# in A_helper.php we have bellow function
$this->view->proc_data = proccess_data($this->view->new_data);
# change the view
$this->view->SetView("ValidData");
}
else
{
throw new \zinux\kernel\exceptions\notFoundException("data not found!");
}
}
}
# PROJECT-ROOT/application/someRoutes.php
namespace application;
/**
* This is a class to add custom-routes to route maps
*/
class someRoutes extends \zinux\kernel\routing\routerBootstrap
{
public function Fetch()
{
/**
* Route Example For This:
* /note/1234/edit/what/so/ever?nonsences=passed => /note/edit/1234/what/so/ever?nonsences=passed
*/
$this->addRoute("/note/$1/edit$2", "/note/edit/$1$2");
}
}
/**
*
* in 'zinux/baseZinux.php' you will see the zinux
* introduces the project's root directory as a plugin
* to itself since the registerPlugin() considers plugins
* under PROJECT-ROOT directory by passing no plugin directory
* it will add the PROJECT-ROOT as a plugin!
*
*/
#