Questions for the new Version (4)
The layout()-Method is automatically called by the dispatcher. In the config.php you define the routes:
PicoraDispatcher::addRoute('/',array('Application','welcome'));
Look into the PicoraDispatcher.php-Code:
static protected $error_handler = array('ApplicationController','error');
static protected $layout_handler = array('ApplicationController','layout');
The Dispatcher calls the welcome-method and then calls the layout-method with one parameter (The Result from the called method (here the welcome-method)).
static public function layout($main){
return self::render('views/layout.php',array('main'=>$main))->display();
}
$main contains the result from the welcome-method. In the array, you define 'main' as a variable for the layout.
I still try to get the ActiveRecord running, but I have similar problems ... I don't know how exactly. Time to RTFS :)
Posted August 20th, 2007 at 6:45am by Aaron
a. How to use active record? There?s a folder "models" but I don?t know how the model-files should look like :/ are there any examples?
I found the PicoraUser class which extends PicroraActiveRecord and I use it as example.
To help you, look this :
File models/BlogPost.php
class BlogPost extends PicoraActiveRecord {
const TABLE_NAME = 'posts';
const PRIMARY_KEY = 'id';
const TITLE_KEY = 'title';
const SYNOPSIS_KEY = 'synopsis';
const CONTENT_KEY = 'content';
const CREATED_KEY = 'created';
const AUTHOR_KEY = 'author';
const CATEGORY_KEY = 'category';
}
File controllers/BlogController.php
class BlogController extends ApplicationController {
public function home(){
$posts = PicoraActiveRecord::findAll('BlogPost');
return self::render('views/blog/home.php', array(
'posts' => $posts,
));
}
public function post($post_id){
$post = PicoraActiveRecord::find('BlogPost', $post_id);
return self::render('views/blog/post.php', array(
'post' => $post,
));
}
}
Posted August 24th, 2007 at 7:10am by SuperDevy
a. How to use active record? There?s a folder "models" but I don?t know how the model-files should look like :/ are there any examples?
I found the PicoraUser class which extends PicroraActiveRecord and I use it as example.
To help you, look this :
File models/BlogPost.php
class BlogPost extends PicoraActiveRecord {
const TABLE_NAME = 'posts';
const PRIMARY_KEY = 'id';
const TITLE_KEY = 'title';
const SYNOPSIS_KEY = 'synopsis';
const CONTENT_KEY = 'content';
const CREATED_KEY = 'created';
const AUTHOR_KEY = 'author';
const CATEGORY_KEY = 'category';
}
File controllers/BlogController.php
class BlogController extends ApplicationController {
public function home(){
$posts = PicoraActiveRecord::findAll('BlogPost');
return self::render('views/blog/home.php', array(
'posts' => $posts,
));
}
public function post($post_id){
$post = PicoraActiveRecord::find('BlogPost', $post_id);
return self::render('views/blog/post.php', array(
'post' => $post,
));
}
}
Posted August 24th, 2007 at 7:10am by SuperDevy
Hi,
I took some time today to check the new Picora version. And I have some questions:
a. How to use active record? There?s a folder "models" but I don?t know how the model-files should look like :/ are there any examples?
b. there is this code in the zip I downloaded:
The root "/" is dispatched to the welcome function. But it renders the "layout.php" too. Why is this? I couldn't find any connections from the render function the this layout-function?
Greetings, Ruben
Posted August 13th, 2007 at 10:22am by ruben