.view.php. all views are stored into project/home/apps/view/controllerName/methodName Directory. The default view of a method is a view whose file name starts with the method name itself. e.g. default view of a method named report of studentController Class will be named as report.view.php and will be located at project/home/apps/view/student/report/report.view.php the report method might have more Views. However the default view is autorendered at the end of method execution and the other views needed to be loaded or rendered by invoking $this->renderView() or $this->loadView() method. Hi! <b><?= $user ?></b><br /> <? foreach($marks as $sub => $mark): ?> You Have got <b> <?= $mark ?> </b> out of <span class="total">100</span> in <span class="sub"><?= $sub ?></span><br /> <? endforeach; ?>
<html><head><title> and other Compulsury tags ?????</big><html>
<head>
<title><?= $params['title'] ?></title>
</head>
<body>
<?= $params['content'] ?>
</body>
</html>
<?= $params['content'] ?> in <body> Tag. all the view are evaluated and their output is concated and stored into $params['content'] variable which is injected into <body> tag. you have also noticed that there is another variable called <?= $params['title'] ?> so from where this comes ? thers is a file which holds common set of parameters (params) which holds the default value of all the params such as title, header, footer, meta, and you can put custom params on that file. First that file is loaded for the shake of default values of params. (However those values can be changed from the Controller latter on Runtime). $params['title'] = "My Page Title";
$params['title] would get replaced by My Page Title //Class homeController ultimately inherits from zigController Class. class studentController extends homeController{ public function main(){ //action logic for main( method here } public function report($id){ $this->user = "Foo"; $this->marks = 94; } }
$this->renderView(theMethodName)). renderView() pulls all member variables from $this ([[Controller]] Instance) and passes them as local variables to the View. so that the view can access $this->user as $user and $this->marks as $marks;
If User doesn't Secify any method http://localhost/zig/student then its main() method is executed . e.g. it behaves like this url http://localhost/zig/student/main
In a controller initialization might be done through Constructor . But If you want to initialize through you need to remember two things.
init() on your Controller that method is executed before other method's execution and after Constructor execution. and init() method have access to ORM Layers and also there is no hassle to call parent class's init() method.init() method on project level Controller homeController Class that will effect all the Controller of that Projec.init($projectName, $controllerName, $methodName, $args).
Zigmoyd has a solution for this situation. That is each method is one file. you can have small methods in studentController Class in student.php. However you can separate big methods in a separate file (which is called Siblings). that will be resolved at the time of request.
for that open the Directory projects/home/apps/controller and create a Directory with the same name of Controller e.g. student here. and now go to projects/home/apps/controller/student and create a file with the same name of the method say report. so you create a file projects/home/apps/controller/student/report.php
and now write the student Sibling class there as the following one.
class studentSibling extends studentController{ }
class studentSibling extends studentController{ function report($id){ //do the same stuff here. } }
studentController Class no codes needed to be changed. $this->user = getUserFromDatabase();
//or
$this->user = getUserNameFromStudentTable();
$this->user = $this->db->student->findNameById($id);
$this->db is the Container of all Table Objects. here student is a Table level Object which represents the std Table. there might me other tables called teacher that will be accessible as $this->db->teacher. e.g. all tables are contained in $this->db Container Object.
and in every table Object you can execute find, fetch, set, etc.... methods that will access database while writting SQL queries on the fly. As you are not writtig the SQL Query in the action logic there is no chance of SQL Injection.
Now one question apears in your mind thats how to attach student or teacher table with the Controller. Thats the job of Models and ORMs
In Zigmoyd Database accessing is not a Direct operation it goes through a database abstraction Layer. which may be configured to use some alias names for tables or columns , Use some permission rules, filter the data before writting to the database, automatically invoke some trigger operations written in PHP with Zigmoyd. and many other Job.
This Layer is configured through some configuration Files called ORM Maps (which are parsed and serialized and Embeded into ORM Classes).
connection as dataConn{
}
table std as Student{
readonly std_id as Id{
}
writable std_name as Name{
required: Student's Name Must not be left Blank
string: Student's Name Must be a String
}
}
table std_score as Marks{
readonly id as Id{
}
writable student_id as StudentId{
required: StudentId Must not be left Blank
int: StudentId Must be an Integer
}
writable subject as Sub{
required: Subject Must not be left Blank
string: Subject Name must be a valid string
}
writable marks as Marks{
required: You must enter the marks obtained by the student
int: Marks Obtained by the Student Must be a string
}
}
etc/conf.d Directory in your Project's Directory. driver = "mysql" database = "manual" host = "localhost" user = "root" psw = "123456"
apps/model/orm directory in your Project's Directory.and one file is created per ORM Map basis.
so if the above mentioned ORM Map's name is studentOrm.orm.map.php ORM Classes for this Map will be created in a file Called studentOrm.orm.php which will be stored in projects/home/apps/model/orm Directory. and now the question is what will they contain.
In studentOrm.orm.php there will be two Classes.
you execute all find, fetch, set, etc.... methods on an object of the Table level Class. and whenever you fetch some data through select like query that returns a row or more than one column e.g. findAll() etc..... the result is provided to you by the RowSet Object.
actually $this->db->student is an Instalce of Student Class. Internally something like $this->db->student = new student(); is done automatically by Zigmoyd while binding the Model wicth the Controller.
as these are just PHP Classes you can add your own custom methods , Triger to customize activity of the Table level and row level Class.
<?php class studentModel extends manualModel{ public function attachOrmMap(){ parent::attachOrmMap('StudentOrm');//attach an Orm Map on file StudentOrm.orm.map.php //you can attach More ORM Maps in the Same way } } ?>
There are a lot more Internal Steps Skiped. the Sequence is not 100% correct to keep it simple.
1.5.6