Re: Alias?

2008-05-05 Thread Davide

Davide wrote:
 unfortunly Router::connect() seems not to work for me. Cake
 1.1.18. It's simply ignored. But you gave me a hint and using
 $Route-connect(...) I can achieve my goal.

 However I have to add a $Route-connect() for each action and it's not
 beautiful and subject to errors. I'm thinking in a workaround
 solution. I will post it here.

Worked a bit on it, but it took too much time for achieving a good
solution so I finally opted for mapping each action in routes.php and
managing the alias in the view action. So finally here is the code[1].

Now I'm asking myself about the utility of AppError if it's disabled
in a production environment. Can someone answer me maybe with a
scenario?

Thanks a lot.
Bye
Davide

1.

//routes.php
...
$Route-connect(/projects/,
array(controller=projects,action=index));
$Route-connect(/projects/add/,
array(controller=projects,action=add));
$Route-connect(/projects/delete/,
array(controller=projects,action=delete));
$Route-connect(...
...
$Route-connect(/projects/view/,
array(controller=projects,action=view));
$Route-connect(/projects/:alias,
array(controller=projects,action=view));

//app/controllers/projects_controller.php
...
   function view($id=null){
  $data = null;
  if(empty($this-params[alias])  is_null($id)){
 $this-cakeError(error404,array($this-params[url]));
  }else{
 if(!is_null($id)){
$data = $this-Project-findById($id);
 }else{
$data = $this-Project-findByAlias($this-params[alias]);
 }
...


-- 
Live life like you're gonna die. Because you're gonna.
William Shatner


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Alias?

2008-04-29 Thread Davide

Joel Perras wrote:
 ...
 For that, use:
 (app/config/routes.php)
 Router::connect('/projects/:name', array('action'='view',
 'name'=null));
 ...

Thanks Joel,

unfortunly Router::connect() seems not to work for me. Cake
1.1.18. It's simply ignored. But you gave me a hint and using
$Route-connect(...) I can achieve my goal.

However I have to add a $Route-connect() for each action and it's not
beautiful and subject to errors. I'm thinking in a workaround
solution. I will post it here.

Thanks for the hint.
Davide

-- 
Live life like you're gonna die. Because you're gonna.
William Shatner


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Alias?

2008-04-28 Thread Davide

I wrote a code (at the bottom) that in case of missingAction will search
in the database and if found then render the proper view.

Everything works fine except when I turn DEBUG=0 (production setup). Now
cake always render the 404 without entering the AppError::missingAction().

How can I do?

Following the code.

Bye and thanks
Davide

/*
 * app/error.php
 */
class AppError extends ErrorHandler{
   function missingAction($params){
  switch($params[className]){
 case ProjectsController:
loadModel(Project);
$model = new Project();
$data = $model-findByAlias($params[action]);
if(is_null($data) || empty($data)){
   parent::missingAction($params);
}else{
   $this-controller-webroot = $params[webroot];
   
$this-controller-set(content_for_layout,$this-requestAction(/projects/view/.$data[Project][id],
array(return)));
   $this-controller-pageTitle = $data[Project][name];
   $this-controller-viewPath = layouts;
   $this-controller-render(ajax);
}
break;
 default:
parent::missingAction($params);
break;
  }

   }
}

-- 
Live life like you're gonna die. Because you're gonna.
William Shatner


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Alias?

2008-04-28 Thread Joel Perras

How about in one line?
In the app/config/routes.php file:

Router::connect('/projects/:id', array('action' = 'view'), array('id'
= '[0-9]+'));

-J.


On Apr 28, 10:31 am, Davide [EMAIL PROTECTED] wrote:
 I wrote a code (at the bottom) that in case of missingAction will search
 in the database and if found then render the proper view.

 Everything works fine except when I turn DEBUG=0 (production setup). Now
 cake always render the 404 without entering the AppError::missingAction().

 How can I do?

 Following the code.

 Bye and thanks
 Davide

 /*
  * app/error.php
  */
 class AppError extends ErrorHandler{
    function missingAction($params){
       switch($params[className]){
          case ProjectsController:
             loadModel(Project);
             $model = new Project();
             $data = $model-findByAlias($params[action]);
             if(is_null($data) || empty($data)){
                parent::missingAction($params);
             }else{
                $this-controller-webroot = $params[webroot];
                
 $this-controller-set(content_for_layout,$this-requestAction(/projects 
 /view/.$data[Project][id],
 array(return)));
                $this-controller-pageTitle = $data[Project][name];
                $this-controller-viewPath = layouts;
                $this-controller-render(ajax);
             }
             break;
          default:
             parent::missingAction($params);
             break;
       }

    }

 }

 --
 Live life like you're gonna die. Because you're gonna.
                                             William Shatner
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Alias?

2008-04-28 Thread Joel Perras

Whoops, didn't see that you wanted to also refer to the unique name of
the project.  So A few more lines.

For that, use:
(app/config/routes.php)
Router::connect('/projects/:name', array('action'='view',
'name'=null));

And in your projects/view controller/action pair:
function view() {
if (empty($this-params['name'])) {
   return $this-setAction('index');
}

$conditions = array('name'=$this-params['name']);
$project = $this-Project-find($conditions);
$this-set(compact('project'));
}


-J.


On Apr 28, 12:41 pm, Joel Perras [EMAIL PROTECTED] wrote:
 How about in one line?
 In the app/config/routes.php file:

 Router::connect('/projects/:id', array('action' = 'view'), array('id'
 = '[0-9]+'));

 -J.

 On Apr 28, 10:31 am, Davide [EMAIL PROTECTED] wrote:

  I wrote a code (at the bottom) that in case of missingAction will search
  in the database and if found then render the proper view.

  Everything works fine except when I turn DEBUG=0 (production setup). Now
  cake always render the 404 without entering the AppError::missingAction().

  How can I do?

  Following the code.

  Bye and thanks
  Davide

  /*
   * app/error.php
   */
  class AppError extends ErrorHandler{
     function missingAction($params){
        switch($params[className]){
           case ProjectsController:
              loadModel(Project);
              $model = new Project();
              $data = $model-findByAlias($params[action]);
              if(is_null($data) || empty($data)){
                 parent::missingAction($params);
              }else{
                 $this-controller-webroot = $params[webroot];
                 
  $this-controller-set(content_for_layout,$this-requestAction(/projects 
  /view/.$data[Project][id],
  array(return)));
                 $this-controller-pageTitle = $data[Project][name];
                 $this-controller-viewPath = layouts;
                 $this-controller-render(ajax);
              }
              break;
           default:
              parent::missingAction($params);
              break;
        }

     }

  }

  --
  Live life like you're gonna die. Because you're gonna.
                                              William Shatner
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Alias?

2008-04-18 Thread Davide

Davide wrote:
 ...
 How can I render the correct page without doing a redirect?

At the moment I've solved in this way. Don't know if it's the right
way but it's working.

Thanks a lot
Bye
Davide

?php
/*
 * app/error.php
 */
class AppError extends ErrorHandler{
   function missingAction($params){
  switch($params[className]){
 case ProjectsController:
loadModel(Project);
$model = new Project();
$data = $model-findByName($params[action]);
if(is_null($data) || empty($data)){
   parent::missingAction($params);
}else{
   $this-controller-webroot = $params[webroot];
   
$this-controller-set(content_for_layout,$this-requestAction(/projects/view/.$data[Project][id],
array(return)));
   $this-controller-pageTitle = $data[Project][name];
   $this-controller-viewPath = layouts;
   $this-controller-render(ajax);
}
break;
 default:
parent::missingAction($params);
break;
  }

   }
}
?

-- 
Live life like you're gonna die. Because you're gonna.
William Shatner


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Alias in CakePHP - ModRewrite Issue

2007-07-01 Thread Grant Cox

To use an Alias with CakePHP, you need to add
RewriteBase /your_alias_name
to the app/webroot/.htaccess file (right after the RewriteEngine On
line).  And you need to have
define ('WEBROOT_DIR', 'your_alias_name');
in your app/webroot/index.php


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---