BasketsController could not be found

Hello

That web site has been build some years ago and the web site has always been working since the web hosting get some issue.
The hosting problem was solved but I have a trouble and I never change any controller.

Inspite of this, I have now an issue


Action BasketsController: could not be found

This happen, when I want to add an item into the basket. When I select a number of itemp and then I press the icon
Screenshot 2021-07-09 at 22.15.46

The error

Action BasketsController::www.sogemat.ch() could not be found

is printed. I observer that is url is

http://www.sogemat.ch/baskets/www.sogemat.ch

The last string www.sogemat.ch, should not be there. If you remove the last string ‘www.sogemat.ch’, you can access the basket

In my BasketsController.php, I have this

	function basketAdd(){
#		$data = array('error'=>true);
		$data = current($this->request->data);
		//debug($data);

		if(empty($data['id'])){
			$this->Session->setFlash("No ID",'notif',array('type'=>'danger'));
#			$data['message']= "No ID";
		}elseif(empty($data['numberof']) OR $data['numberof']==0){
			$this->Session->setFlash(__("Le nombre d'article ne doit pas être vide ou plus grand que zéro"),'notif',array('type'=>'danger'));
		}else{
			$this->loadModel('Article');
			$this->Article->id = $data['id'];
			$art = $this->Article->find('first',array('conditions'=>array('id'=>$data['id'])));
			if(empty($art)){
#				$data['message'] = "That article does not exist";
				$this->Session->setFlash("That article does not exist",'notif',array('type'=>'danger'));
			}else{
				$this->Session->write('Basket.'.$data['id'],$data['numberof']);
				#$this->Session->write('Baskettot.'.$data['id'],$data['numberof']);
				//debug($this->Session->read('basket'));
#				$data['message'] = "The product (".$id.") has been add to your basket";
#				$data['error']= false;
//				$this->Session->setFlash("The product (".$id.") has been add to your basket",'notif');


			}
	
		}
#		$this->set('_serialize', $data);
#		echo json_encode($json);

		$this->redirect($this->referer());
		
	}

The HTML form is as the following

   <div class="col-xs-6 col-sm-6 col-md-6">
                <?php if($this->Session->read('Arti.basketstatus')){ ?>  
                 
                    <?php echo $this->Form->create(null, array(
                        'url' => array(
                            'controller' => 'baskets', 
                            'action' => 'basketAdd'
                            ),
                        'style'=>'padding:0px;',
                        'id'=>'AddBasket'.$v['id'],
                        'inputDefaults' => array(
                            'label' => false,
                            'div' => false
                            )
                        )); 
                    ?>
            
                        <?php echo $this->Form->input('id',array('id'=>$v['id'],'label'=>null,'type'=>'hidden','value'=>$v['id'] )); ?>
                        <?php echo $this->Form->input('numberof',array('id'=>'numberOf'.$v['id'],'label'=>false,'type'=>'number','class'=>'numberof','style'=>'','value'=>1)); ?>
            </div>
            <div class="col-xs-6 col-sm-6 col-md-6">

                    <?php 
                    $options = array(
                        'label' => '',
                        'div' => false,
                        'class'=>'addToBasket'
                    );
                    echo $this->Form->end($options);
                    ?>
                <?php } ?>    

                </div>
            </div>

Why? Why the string www.sogemat.ch is added after /baskets/ ?
It should not

Many thanks for your help

Apparently, when I add an item, after the issue the item is add to the basket.
At the right site, the basekt box show an item.

If you click on Checkout, the items is/are listed.

If you try to delete an item, the problem occur again. It look to be an problem with the forms

Someone could help me with this issue, I have no idea how to solve it and I I have to go ahead. Many thanks

What’s your baseUrl setting?

Dear Zuluru
Thanks a lot for your reply and sorry to respond later. I was not available the last 3 hours.

To be honnest, it’s a long time, I have not work on that web site. I hope a provide you the right answer.

In the file ‘core.php’, I have this (commented)

/**
 * To configure CakePHP *not* to use mod_rewrite and to
 * use CakePHP pretty URLs, remove these .htaccess
 * files:
 *
 * /.htaccess
 * /app/.htaccess
 * /app/webroot/.htaccess
 *
 * And uncomment the App.baseUrl below:
 */
	//Configure::write('App.baseUrl', env('SCRIPT_NAME'));

/**

my htaccess file at root is

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

my htaccess file at app/ is

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
</IfModule>

my htaccess file at webroot/ is

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

In my route.php file, I have

Router::parseExtensions('rss');

	Router::connect('/', array('controller' => 'pages', 'action' => 'index', 'home'));
	//Router::connect('/page/:slug-:id',array('controller'=>'pages','action'=>'show'),array('pass'=>array('id','slug'),'id'=>'[0-9]+','slug'=>'[a-z0-9\-]+'));
	Router::connect('/:slug-:id.html',array('controller'=>'pages','action'=>'show'),array('pass'=>array('id','slug'),'id'=>'[0-9]+','slug'=>'[a-z0-9\-]+'));
	Router::connect('/article/:slug-:id',array('controller'=>'articles','action'=>'show'),array('pass'=>array('id','slug'),'id'=>'[0-9]+','slug'=>'[a-z0-9\-]+'));
	Router::connect('/categorie/:slug',array('controller'=>'articles','action'=>'category'),array('pass'=>array('slug'),'slug'=>'[a-z0-9\-]+'));
	Router::connect('/tag/:name',array('controller'=>'articles','action'=>'tag'),array('pass'=>array('name'),'name'=>'[A-Za-z][a-z0-9\-]+'));

But as I say, I never changed any things and the web site was always working since the hosting got server problem which is now solved.

I hope you can help

What version of Cake is this app built on? And did the hosting problem fix involve any change in PHP version? And how comfortable / familiar are you with debugging PHP scripts?

Hello, I have an old version 2.4.2.
I am not very sure about the PHP version, I have to check.
Yes, I am used to use PHP, but some doubt about debuging php with CakePHP

I never used v2.x, so I don’t have any concrete things to try. You’ll want to look at what function is being used to generate those links ($this->Html->link or the like?), then look at that function, and put some debugging in it to see where it’s going wrong. That should pretty quickly point you at what bit of configuration or environment it’s looking at and making the wrong determination from.

Ok, thanks,

HOw can debug this line

$this->redirect($this->referer());

It look to be the gulty.

Other the things I do not understand, If I decommented the line

‘debug($data);’

noting is printed

function basketAdd(){
#		$data = array('error'=>true);
		$data = current($this->request->data);
		//debug($data);

		if(empty($data['id'])){
			$this->Session->setFlash("No ID",'notif',array('type'=>'danger'));
#			$data['message']= "No ID";
		}elseif(empty($data['numberof']) OR $data['numberof']==0){
			$this->Session->setFlash(__("Le nombre d'article ne doit pas être vide ou plus grand que zéro"),'notif',array('type'=>'danger'));
		}else{
			$this->loadModel('Article');
			$this->Article->id = $data['id'];
			$art = $this->Article->find('first',array('conditions'=>array('id'=>$data['id'])));
			if(empty($art)){
#				$data['message'] = "That article does not exist";
				$this->Session->setFlash("That article does not exist",'notif',array('type'=>'danger'));
			}else{
				$this->Session->write('Basket.'.$data['id'],$data['numberof']);
				#$this->Session->write('Baskettot.'.$data['id'],$data['numberof']);
				//debug($this->Session->read('basket'));
#				$data['message'] = "The product (".$id.") has been add to your basket";
#				$data['error']= false;
//				$this->Session->setFlash("The product (".$id.") has been add to your basket",'notif');


			}
	
		}
#		$this->set('_serialize', $data);
#		echo json_encode($json);

		$this->redirect($this->referer());
		
	}

debug only generates output if you’ve got debugging enabled in the config.