Skip to content
Raphaël Emourgeon edited this page Nov 3, 2013 · 3 revisions

Je propose l'api suivante :

<?php
    require dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Data' . DIRECTORY_SEPARATOR . 'Core.link.php';
 
 
    from('Sohoa')
        ->import('Framework.Bootstrap');
 
 
    $sohoa = new \Sohoa\Framework\Bootstrap(); // On lit un fichier de configuration qui nous configurera View / Database / Quelques routes ?
    $sohoa->router // Return \Hoa\Router\Http()
        ->get('call', '/(?<_call>[^/]+)/', 'main', 'index')
        ->get('home', '/', 'local', 'index');
    $sohoa->dispatcher; // Return \Hoa\Dispatcher\Basic()
    $sohoa->view; // Return \Hoa\View\Viewable
 
 
    class Main extends \Sohoa\Framework\Controller
    {
        // what about pre-action filter ?
        // for example, we are in a Posts controller, we want to load current post for edit/update/delete action

        // About pre-action filter
        // Start reflexion about : global filter
        protected function pre($action){
           switch($action) {
             // ...
           }
        }
        
        or
        // An local filter
        protected function PreIndexAction(){
        
        }
        
        or
        // Annotation
        /**
          * Pre-action : doSomething
          * 
          */

        // End reflexion

        public function IndexAction()
        {
            // form
            $this->form('#anFormId')->getData(); // Ou le formulaire est écrit en dans un snippet XYL
            $this->form('#anFormId')->isValid();
                    // ....
            $this->form('#anFormId')->fill($_POST);        
       
            // redirect
            $this->getBootstrap(); // Return \Sohoa\Framework\Bootstrap()
            $this->getBootstrap()->router->redirect('http://foo.bar');
            $this->redirect('..'); // Un alias de la précédente méthode comme Redirector by iraphael ;)
            
            // render view
            $this->render(); // Render of hoa://Application/View/Main/Index.xyl
            $this->render('hoa://Application/View/Main/Foo.xyl'); // Alias
            
            // sample with data
            $this->render(array('data1' => $data1)); // render of hoa://Application/View/Main/Index.xyl with data1
            $this->render('hoa://Application/View/Main/Foo.xyl', array('data1' => $data1));
            
            // what about rendering with/without layout ?            
            
            $this->layout('hoa://Application/View/Main/Foo.xyl');
            $this->render(); // Rend hoa://Application/View/Main/Foo.xyl && hoa://Application/View/Main/Index.xyl
      
            // what about rendering text (without view), JSON, XML... ?           
            // Simple echo ?
        }
    } 

A vous de la modifier pour obtenir l'api parfaite

Clone this wiki locally