PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, April 21, 2022

[FIXED] How to route to a specific method in cakePHP?

 April 21, 2022     cakephp, cakephp-2.3, cakephp-3.0, cakephp-routing     No comments   

Issue

my route:

Router::connect('/', array('controller' => 'users', 'action' => 'homepage'));

Router::connect('/admin', array('controller' => 'users', 'action' => 'dashboard', 'admin' => true));

my Controller

class BrandsController extends AppController {

/**
 * Components
 *
 * @var array
 */
public $components = array('Paginator', 'Session', 'Flash');


var $paginate = array('limit' => 100);

/**
 * admin_index method
 *
 * @return void
 */
public function admin_index()
{      
  index method      
}
 public function admin_searches() 
{
     searches method
}     

My link

<?php echo Router::url(array('controller' => 'brands', 'action' => 'searches')); ?>

I have a admin_searches.ctp file which has hello world text as well.

Problem is: When i have a href link as,

<a href="<?php echo Router::url(array('controller' => 'brands','action' => 'admin_index')); ?>">Brands List</a> 

it works fine and displays the index page. Now when i want to display a search page "admin_searches,ctp" it wont. How may I route in the link or amend route file so that when i call the above link it invokes search method in my controller class


Solution

This is a authentication issue. Everytime i try to create a new file eg: admin_search and a controller method called admin_search it echoes "you are not permitted to acess this location." Therefore, to overcome this issue i had to include authentication of a method in beforeFilter();

public function beforeFilter() {
            parent::beforeFilter();
            $this->Auth->allow('admin_searches');
    }


Answered By - mario
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,261,715

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing