Missing argument 1..

It’s driving me mad! It’s probably some typo again somewhere but’t I can’t find the problem.

Trying to call a function in the controller from the view, but I only get:

"Missing argument 1 for ProductionordersController::getPrerequisite(), called in C:\xampp\htdocs\framework\base\CComponent.php on line 112 and defined"

The controller:


public function getPrerequisite($order)

{

	$notpossible = false;

		

	$criteria = new CDbCriteria;

	$criteria->condition = 'primaryorder = :id';

	$criteria->params = array(':id'=>$order);

	

	$orderstructures = Orderstructures::model()->findAll($criteria);

		

	foreach($orderstructures as $structure)

	{

		if($structure->suborder0->status->displaycategory == 1)

			$notpossible = true;

	}

		

	if($notpossible)

		return 'En eller flera underliggande produkter är ännu inte färdiga!';

}

the view:


<h1>#<?php echo $model->Id; ?></h1>


<?php echo $this->prerequisite($model->Id); ?>


<?php echo $this->renderPartial('_cuttersFormview', array('model'=>$model,'strucModel'=>$strucModel)); ?>

First try to comment the code which is casing the issue and check the value of the id.

Second solution is that

set the $order to null and have a check value of it there to fetch the data from sql server.

Thanks

Thank you for the fast reply PeRoChAk, you led me in the right direction.

It appears that it didn’t like it when I tried to call it with $this->prerequisite so I had to change to

$this->getPrerequisite.

So calling a function getSomething() by using $this->something only works for models and not controllers?

As both are classes so, we can call them and it should work too.

But consider the $this keyword.

I wonder if the issue has to do with the fact that you are taking an argument? I have two kinds of methods in my /model/ file: if I don’t include the get with methods that require an argument, I also get the “missing argument error”: if I include the “get”, the error vanishes.

The problem is you’re treating getPrerequisite() as a virtual property when it’s actually just a normal method that happens to start with “get”, it’s not a true getter because its argument is not optional.

Thanks for a clear explanation!