Could you be kind enough to give a link because I don't seem to be able to find it…?
Also I was ready this excellent post of yours
[url=“PHP Controllers - 1 - Developers' Corner - CS-Cart Community Forums”]PHP Controllers - 1 - Developers' Corner - CS-Cart Community Forums
but I can't find the next one (about the templates)…
That's the first post of the series I was talking about. Just do a search by author and restrict it to the developer's corner forum and you should bet a nice listing…
Got it!! Thanx a lot, great job!!
Hello!
First I'll say thank you to the likes of CSCart dev'ers like 'tbirnseth' and others who are active on this forming helping people new to CSCart figure out how the system works. I find the documentation on the main site quite lacking.
Secondly, please pardon my ignorance!
In trying to gain an understanding of how the model>view>controller concept works within CSC specifically regarding Addons I have done the following:
Followed example given here:
http://docs.cs-cart…add-on-tutorial
I have a functioning 'Block' in place on the homepage setup in the file structure as:
~/skins/basic/customer/addons/my_addon/blocks/static_templates/my_addon.tpl
By functioning I mean that I placed the block in the homepage section of the design GUI in the Admin Panel. And, when I go to my homepage, whatever html/text I have in my_addon.tpl get's displayed on the page.
my_addon.tpl:
```php
{** block-description:my_addon **}
some content
```
So, onto more useful concepts. In trying to understand how the flow works I setup a my_addon.php controller file in:
~/addons/my_addon/controllers/customer/my_addon.php
I also have a func.php in:
~/addons/my_addon/func.php
Because I was going to try to create a function that returns an arbitrary value to the my_addon.php controller. But I couldn't even get that far.
So, my first question (problem), is that I can't get my controller to communicate with my template (.tpl). I have:
my_addon.php
```php
if( !defined('AREA') ) die('Access denied');
$some_value = 'Hello';
$view->assign('passed_value', $some_value);
?>
```
And I updated my my_addon.tpl:
```php
{** block-description:my_addon **}
my value: {$passed_value}
```
This does not work...
I've been reading a bunch on this forum but I just can't understand enough to get this example working. Can someone please help with what has got to be super simple? Also, if you could go one step further to explain (give example code) for how to create a simple function in func.php and how to call that function from my controller and manipulate the returned value in the controller php.
I thank you in advance!
The 'mode' specifies the 'view' that will be used. So if your controller was called like:
?dispatch=my_addon.view
and your my_addon.php did something like:
if( $mode == 'view' && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
Registry::get('view')->assign('passed_value', “this is my value”);
}
return array(CONTROLLER_STATUS_OK);
What will happen when this returns is that will look for a template named 'view.tpl' in
skins/
If you don't want this to go to its own view, you would do an
return array(CONTROLLER_STATUS_REDIRECT,
instead of the OK
If your block is available wherever you redirect to, then the {$passed_value} will be available to your block.
Hello every one,
I am trying to create new block, named is “accountâ€, I have saved data in admin area succesful and i want to show data in storefront (home page), source structure in below:
1/Addon:
MODEL: addons\account\func.php
function fn_account_get(){
$account = db_get_array("SELECT * FROM ?:account");
return $account;
}
?>
[u]CONTROLLER:[/u] Addons\account\controllers\customer\account.php
if ( !defined('AREA') ) { die('Access denied'); }
if($mode=='account' && $_SERVER['REQUEST_METHOD'] != 'POST'){
$account=fn_account_get();
$view->assign('account', $account);
return array(CONTROLLER_STATUS_OK);
}
?>
[u]SCHEMAS:[/u] addons\account\schemas\block_manager\blocks.post.php
if ( !defined('AREA') ) { die('Access denied'); }
$schema['account'] = array (
'content' => array (
'items' => array (
'remove_indent' => 'true',
'hide_label' => 'true',
'type' => 'function',
'object' => 'account',
'items_function' => 'fn_account_get',
),
),
'templates' => array(
'addons/account/blocks/account.tpl' => array(),
),
'wrappers' => 'blocks/wrappers',
);
?>
[u]VIEW:[/u] var\skins_repository\basic\customer\addons\account\views\account\account.php
{foreach from=$account item="acc"}
{$acc.name}
{/foreach}
[color=#ff0000][u]My Problem:[/u][/color]
The block after installed, it’s show OK with URL: [url="http://localhost/working/cscart/index.php?dispatch=account.account"]http://localhost/working/cscart/index.php?dispatch=account.account[/url]
BUT I want it show on homepage: [url="http://localhost/working/cscart/index.php"]http://localhost/working/cscart/index.php[/url]
How can i config ? Please suggest for me. Thank you very much
Hi,
I came across this issue and I tried to solve it as @tbirseth mentioned, but when I tried the url (index.php?dispatch=custom_code.my_info) it shows 404 page error.
Any Ideas on this one?
I added a custom_code addon in my cscart 4.x installation and added the design code in design folder view.tpl and tried the dispatch url.
Its not working.
Addon Folder - app/addon/custom_code/controllers/customer/custom_code.php
Design Folder - design/themes/theme_name/templates/addon/custom_code/views/custom_code/view.tpl
What am I doing wrong?
The name of the template is derived from the “mode” of the dispatch. I.e. if you are using:
dispatch=custom_code.my_info
then the template that will be called is:
design/themes/theme_name/templates/addons/custom_code/views/custom_code/my_info.tpl
If you do not want it to get to the template file then you can just redirect from your custom_code controller when the mode my_info is detected.
Note that if you are POSTing data to custom_code.my_info you MUST redirect for things to work properly. Cs-cart does not behave properly when navigating from a POST request.
Hi, Thanks for the reply @tbirseth.
So, I just managed to make my controller work just fine. Managed to insert the product data in my custom table.
The issue that I m facing is after my controller mode my_info does its job, I would like to show a notification for which I've a page notification.tpl in my design folder ([color=#282828][font=arial, verdana, tahoma, sans-serif]design/themes/theme_name/templates/addon/custom_code/views/custom_code/components/notification.tpl)[/font][/color]
[color=#282828][font=arial, verdana, tahoma, sans-serif]Any suggestion [/font][/color][color=#282828][font=arial, verdana, tahoma, sans-serif] on how to do this.?[/font][/color]
[color=#282828][font=arial, verdana, tahoma, sans-serif]I've tried adding the notification code in a similar way below.[/font][/color]
if (defined('AJAX_REQUEST')) {
$title = “Product Added”;
$msg = Registry::get('view')->fetch('addons/custom_code/views/custom_code/components/notification.tpl');
fn_set_notification('I', $title, $msg, 'I');
}
It doesn't seem to work fine. But sometimes when I refresh the page I'm getting the notification shown in my index page . Works wierd. I want the notification to be shown only when my controller mode my_info is called.
Any suggestions to make it work ?