how to create a link to a module in yii ? - yii

Hello and thanks for reading.
I was wondering how i can link to a file from my main site to a module
eg ;
if i am in protected/views on a file and i want to link to protected/modules/user/profile where i call an action.
Now i get an error that states that action user does not exists.
How can i create a link to a module following the following yii sintax ;
<?php echo CHtml::link('Link Text',array('link to module',
'param1'=>'value1')); ?>

<?php echo CHtml::link(Yii::app()->createurl('Module/Controller/Action'),array(
'param1'=>'value1')); ?>

this may help with combining CHtml::link with a link to a module and it's controller/action combination:
echo CHtml::link("click here",
Yii::app()->createurl('/module/controller/action', array(
'id' => $model->id // Params
))
);

i managed to figure it out i tried to put this and it works ''/user/profile''
anybody has other ideas let me know

Related

WHMCS how to find right tpl files in pages

i'm using WHMCS and i want to make some changes in part of the page but its so hard and takes so much time for me to find the right tpl file and edit it in the template.
for example for this "search for domains" tab in this url =>
example.com/cart.php?a=add&domain=register
where is the .tpl file.
For example.com/cart.php?a=add&domain=register the file is at templates/orderforms/standard_cart/adddomain.tpl
In general, when url has cart.php, the file in cart template.
Also, you can add the following to hooks to tell you which tpl file was used for current page.
1- Create file includes/hooks/tpl_locator.php
2- Add the following code:
<?php
add_hook('ClientAreaPage', 1, function($vars) {
error_log(print_r([$vars['currentpagelinkback'],$vars['templatefile']], true), 3, __DIR__.'/tpl_file_location.log');
});
3- Visit the page you want to know which tpl file is used.
4- Result will be at file includes/hooks/tpl_file_location.log, sample below:
Array
(
[0] => /cart.php?a=add&pid=1&
[1] => configureproductdomain
)
This was tested on WHMCS 8.0
The tpl for cart.php?a=add&domain=register is actually located at /whmcs/templates/orderforms/standard_cart/domainregister.tpl if I understand your question.

Error 400 Your request is invalid in yii if i am creating link

I'm pretty new to Yii, so this might be a silly question. I must be missing something somewhere. Plz help me out.
I have just written a simple code while I'm learning Yii.
I have a spark controller which has an action that looks like this:
public function actionDownload($name){
$filecontent=file_get_contents('images/spark/'.$name);
header("Content-Type: text/plain");
header("Content-disposition: attachment; filename=$name");
header("Pragma: no-cache");
echo $filecontent;
exit;
}
Now I have enabled SEO friendly URLs and echo statement in the view file to display the returned download file name.
But when I go to the URL,
SITE_NAME/index.php/spark/download/db5250efc9a9684ceaa25cacedef81cd.pdf
I get error 400 - your request is invalid.
Plz let me know if I am missing something here.
Yii keeps an eye on the params you pass into an action function. Any params you pass must match what's in $_GET.
So if you're passing $name then you need to make sure there's $_GET['name'] available.
So check your URL manager in /config/main.php, and make sure you're declaring a GET var:
'spark/download/<name:[a-z0-9]+>' => 'site/download', // Setting up $_GET['name']
Otherwise change your function to the correct param variable:
public function actionDownload($anotherName){
}
Did you create the URL correct? You should do it best with
Yii::app()->createUrl('/spark/download',array('name'=>$filename));
Make sure if you are properly supplying the parameter name ($name) in your request.
Use
SITE_NAME/index.php/spark/download/name/db5250efc9a9684ceaa25cacedef81cd.pdf
or
SITE_NAME/index.php/spark/download?name=db5250efc9a9684ceaa25cacedef81cd.pdf
instead of just SITE_NAME/index.php/spark/download/db5250efc9a9684ceaa25cacedef81cd.pdf

Yii multiselect widget

I have the following code that produces a jquery ech multiselect menu widget in Yii. (Eric Hynds multiselect).
I have downloaded the extension and unzipped in extensions folder
and my folder structure is My_lokal_Yii/protected/extensions/EchMultiSelect/EchMultiSelect
this is my view file code..
<?php $this->widget('ext.EchMultiselect.EchMultiselect', array(
'model' => $model,
'dropDownAttribute' => 'color',
'data' => $list,
'dropDownHtmlOptions'=> array(
'style'=>'width:378px;',
),
));?>
and in config/main.php i have imported the extension as
'import'=>array(
'application.models.*',
'application.components.*',
'application.extensions.EchMultiselect.*'
),
But i am getting error that "Alias "ext.EchMultiselect.EchMultiselect" is invalid. Make sure it points to an existing PHP file and the file is readable."
I have given all the permissions for the EchMultiselect file.
Please help me in this.. Thank you.. I tried a lot but did't get the exact result..
my folder structure is
My_lokal_Yii/protected/extensions/EchMultiSelect/EchMultiSelect
but in your config/main.php, there is:
... 'application.extensions.EchMultiselect.*'
------------------------------------^
It lacks the capital letter "s" and therefore the exact path/naming to/of your extension, I had the same "problem" with it ;-) , maybe it helps...
Greetings

giving ID and/or other variables for each php page

Is there a simple php coding way how to add variable(s) "dynamic or fixed types" to include in a link so that the link doesn't show up as a clean url. And this an example of what I mean:
www.example.com/folder/sense/home
To
www.example.com/folder/sense/index.php?type=article&id=25&date_written=20100322
Or
www.example.com/folder/sense/index.php?id=25
I hope it is clear what I'm up to.
P.S: this is all in Apache
Thanks
The http_build_query function (http://php.net/manual/en/function.http-build-query.php) will convert an array of data into an urlencoded string of variables.
Example from the link above:
<?php
$data = array('foo'=>'bar',
'baz'=>'boom',
'cow'=>'milk',
'php'=>'hypertext processor');
echo http_build_query($data) . "\n";
?>
will output
foo=bar&baz=boom&cow=milk&php=hypertext+processor
I am not sure i get it, but if you use a form with post, $_POST array will keep variables and they will not be visible in the url

File upload with Yii's ActiveForm

I am trying to use Yii's ActiveForm to create a basic registration page with an image upload field. However, I am running into problems. I am using the following code to create the form tags:
$form=$this->beginWidget('CActiveForm', array(
'id'=>'activity_form',
'enableAjaxValidation'=>true,
'stateful'=>true,
'enctype'=>'multipart/form-data'
));
The above code produces the following error message in Yii:
Property "CActiveForm.enctype" is not defined
I've also tried:
$form=$this->beginWidget('CActiveForm', array(
'id'=>'activity_form',
'enableAjaxValidation'=>true,
'stateful'=>true,
array('enctype'=>'multipart/form-data')));
as well as:
$form=$this->beginWidget('CActiveForm', array(
'id'=>'activity_form',
'enableAjaxValidation'=>true,
'stateful'=>true),
array('enctype'=>'multipart/form-data')));
But neither of these work.
Any ideas as to what could be wrong? Can I use beginWidget to create a multipart form with file upload capabilities? What's the format I should follow for this? I can't seem to find any answers in the documentation or the forums.
Thanks!
Never mind. I found the solution to this. The trick is to use htmlOptions like so:
$this->beginWidget('CActiveForm', array(
'id'=>'activity_form',
'enableAjaxValidation'=>true,
'stateful'=>true,
'htmlOptions'=>array('enctype' => 'multipart/form-data')
));