Yii: renderPartial can't load view when using CAction - php

I am trying to use the renderPartial method within a action class.
The method is unable to find the view.
The view is within the root of the app /views/invoice/view.php
<?php
class InvoiceAction extends CAction {
public $invoice_id = 0;
public function run() {
Yii::app()->controller->renderPartial('/invoice/view');
}
}

Switching to the following code will work fine:
Yii::app()->controller->renderPartial('//invoice/view');

Switched to the following code and it worked :
Yii::app()->controller->renderPartial('application.views.invoice.view');

Related

Call Model from custom component into Joomla 4 controller

I have been working in Joomla 4.2.5 and I need to convert my custom components from Joomla 3 to Joomla 4 compatible. I am trying to call model from my custom component into Joomla user controller file, but I am getting an error and code does not perform execution.
I have tried few code but it is not working.
Joomla 3 code for call model from custom component into user controller:
UserController.php
JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_mycomponent/models', 'MycomponentModel');
$model = JModelLegacy::getInstance('Mycomponent', 'MycomponentModel');
Here is my model file code in
components/Mycomponent/Models/mymodel.php
class MycomponentModelmycomponent extends JModelLegacy
{
public function somefunction(){
}
}
Below is my attempt to convert above code into Joomla 4:
UserController.php
Use Joomla\CMS\MVC\Model\BaseDatabaseModel;
class UserController extends BaseController
{
public function login()
{
login functions....
BaseDatabaseModel::addIncludePath(JPATH_SITE .'/components/com_mycomponent/models');
$model = BaseDatabaseModel::getInstance('Mycomponent', 'MycomponentModel');
$model->myfunction($argument);
}
}
components/Mycomponent/Models/mymodel.php
namespace Joomla\Component\mycomponent\Site\Model;
use Joomla\Registry\Registry;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\ListModel;
class IbousersModelIbousers extends ListModel
{
public function myfunction($argument){
}
}
But it is not working, can anyone suggest me what is wrong or how can I call model from another component in Joomla 4?
In Joomla4, you get the model from the MVCFactory.
So the equivalent of:
BaseDatabaseModel::addIncludePath(JPATH_SITE .'/components/com_mycomponent/models');
$model = BaseDatabaseModel::getInstance('Mycomponent', 'MycomponentModel');
Would be:
$mvc = Factory::getApplication()->bootComponent('com_mycomponent')->getMVCFactory();
$model = $mvc->createModel('MycomponentModel', 'Site');

Laravel 4 how can I call another controller

I'm trying to call an external controller which is outside of App. Example path project\domains\service\onion\controllers\SignupController.php. In my App->controller got this class exampleController. So I try to get the function from SignupController.
Code
use Project\domains\service\onion\controllers\SignupController;
Class exampleController extends \RestController
{
public function grap()
{
$result = App::make('SignupController')->store();
}
}
Got error: Project\domains\service\onion\controllers\SignupController not found
You can try simply
(new SignupController())->methodOfSignupController();

How to use a public method from a controller to another controller in codeigniter?

I have 2 controllers, Listes.php and Campagnes.php. I want to use a method from the Listes controller in a method from the campagnes, is it possible? And is it possible to pass some parameters to it?
I use Codeigniter 3.
I tried some answers I found here but none of them worked.
I also this in the campagnes.php controller :
include_once (dirname(__FILE__) . "/Listes.php");
class Campagnes extends Listes {
public function listes_recap()
{
$result = parent::add($parameter1, $parameter2);
}
}
and in the Listes.php controller :
class Listes extends CI_Controller {
public function add($parameter1, $parameter2)
{
code here...
}
}
Thanks in advance for you're help.
There are a couple ways to achieve the results you want. But calling one controller from another is NOT the way to go. The "best" way to do it depends on what actually happens in the function that both controllers will use.
The first way is to create a "helper" that each controller will load and then use.
file: /application/helpers/list_add_helper.php
defined('BASEPATH') OR exit('No direct script access allowed');
if ( ! function_exists('add'))
{
function add($parameter1, $parameter2)
{
code here...
}
}
Use it in the controller like this
$this->load->helper('list_add');
$result = add($one, $two);
The second way is to create a custom library (class)
file: /application/libraries/List_adder.php
class List_adder
{
public function add($parameter1, $parameter2)
{
//code here
}
}
Used in any controller
$this->load->library('list_adder');
$result = $this->list_adder->add($one, $two);
If you need to use CI code in your custom library you have a little more work to do. Read all about it HERE.
calling one controller method from another controller is not a good programming strategy

Running a sample using Laravel 4

I am trying to run a sample example using Laravel 4 and i am getting errors like, class not found. Can someone help me out here?
controller
file name : authors.php
<?php
class Authors extends BaseController {
public $restful = true;
public function get_index() {
return View::make('authors.index');
}
}
?>
routes.php
Route::get('authors', array('uses'=>'authors#index'));
Views/authors/index.php
<h1> First program in Laravel 4 </h1>
Fitst of all your authors!=Authors, so make sure of your conyroller name in the Route.
And if you want RESTful controller then you can define your route like Route::controller('baseURI','ControllerName'),
Laravel allows you to easily define a single route to handle every action in a controller using simple, REST naming conventions. First, define the route using the Route::controller method..
To know more check restful-controllers
In your example you have to rename your get_index method to getIndex as L4 is camelCase
//AuthorsController.php
class AuthorsController extends BaseController {
public $restful = true;
public function getIndex() {
return View::make('authors.index');
}
}
//route.php
Route::controller('authors', 'AuthorsController');

Default RESTful CakePHP routing gives Missing Controller Method error

I am following this tutorial http://book.cakephp.org/2.0/en/development/rest.html to get up and running with REST in my CakePHP application.
I have added the following to my routes.php file:
Router::mapResources(array('fantasyPicks', 'fantasyPlayers'));
Router::parseExtensions();
In each of my controllers, I have included the RequestHandler component and also setContent to json in the beforeFilter() callback. It looks something like this:
class FantasyPicksController extends AppController {
public $components = array('RequestHandler');
public function beforeFilter() {
parent::beforeFilter();
$this->RequestHandler->setContent('json','text/x-json');
$this->layout = 'json/default';
}
public function index() {
$fantasyPicks = $this->FantasyPick->find('all');
$this->set('json', $fantasyPicks);
$this->render('/json/data');
}
...
My json/data view simply echos json_encode:
<?php echo json_encode($json); ?>
After all of this, navigating to /fantasyPicks/view/1 works as expected. However, /fantasyPicks/1 is giving me the following error:
Missing Method in FantasyPicksController
Error: The action 1 is not defined in controller FantasyPicksController
Error: Create FantasyPicksController::1() in file: app\Controller\FantasyPicksController.php.
<?php
class FantasyPicksController extends AppController {
public function 1() {
}
}
Does anyone know what I am doing incorrectly? Any help is appreciated!
You have to use proper controller naming conventions when accessing the page.
http://book.cakephp.org/2.0/en/getting-started/cakephp-conventions.html
Refer to the URL considerations section. So you should be going to /fantasy_picks/1 and it will work properly.

Categories