Embed Yii module page in Facebook app - php

I've created Yii quiz module which I also want to use in Facebook app (Facebook side).
It can be done trough iframe, but generated page have got also menus and many other unnecessary (in this case) stuff. Is it possible in Yii to show only generated module code without rest of the website?

Try and use a different layout for that module. First you can add a layout folder and layout files to that module, say : /protected/modules/quiz/views/layouts/quizlayout.php. So this new quizlayout.php should be your layout for all the views in this module.
To do that you can set the layout property of the quizmodule in the QuizModule class's init(), like so (in QuizModule.php):
class QuizModule extends CWebModule {
public function init() {
// this method is called when the module is being created
// you may place code here to customize the module or the application
// import the module-level models and components
$this->setImport(array(
'quiz.models.*',
'quiz.components.*',
));
$this->layout='quizlayout';
}
//...
}
Now by default, gii generated modules' controllers are subclasses of the Controller class in component/Controller.php file. And that Controller class defines a layout, so if you have that same structure, then the above method will not work, and you'll have to override the layout within your modules' controllers. However instead of going inside each controller and adding a line, you can instead do this in the beforeControllerAction($controller, $action) function in QuizModule.php :
public function beforeControllerAction($controller, $action) {
if(parent::beforeControllerAction($controller, $action)) {
// this method is called before any module controller action is performed
// you may place customized code here
$controller->layout='quizlayout';
return true;
}
else
return false;
}
Edit:
Of course your quizlayout.php should not have code for menus, and any extra stuff, but at the very least the echo $content line should be there, as also mentioned in eskimo's answer.

In you protected/views there is a file called "main.php"
This is your main layout file, that gets rendered around any view called by $this->render
To remove the menu etc.. remove everything within the body except for the line:
<?php echo $content; ?>
Obviously leave in all the stuff in the head (.css files etc...)

Related

Using renderWith() to render core template with custom layout

I have a class
class ModuleController extends Controller {
private static $allowed_actions = array(
'index'
);
public function index(SS_HTTPRequest $request) {
return $this->renderWith(array("Module/HomePage", "Page"));
}
}
And two templates, one is Page.ss and another is Layout/Module/Homepage.ss. In Page.ss I have a bunch of html and $Layout. Looking through other areas online I would have expected the page to render according to Page.ss and the layout variable to render with Layout/Module/HomePage.ss however it just renders with Page.ss. How can I get my page to render with the base template of Page.ss and render the $Layout with my controller defined layout?
EDIT
So if I put the Homepage.ss up one level (i.e. no 'Module' directory) this code works. Is it possible to have directories in the Layout directory as I think this folder will get messy overtime without some structure. It also seems strange that the folder path works when setting the template but not the layout.
EDIT 2
Looks like This is a core problem I've just discovered a different way and looks to be addressed in SS4 so looks like this can't be done in SS3.

how to retrieve data in view Independent of controller in codeigniter

I have a sidebar in my site that receive some information from db and I can't use controller for retrieve data because I have different controller and same sidebar. How can I print this data in view page.
when I wrote in P.h.P code in the view it shows an error that it cant define variables.
How could I do this?
When you find that you need the same code in many different controllers a "custom library" (class) is the perfect choice. Documentation for creating your own libraries is found HERE.
Controllers should be using models to get data from the database. Custom libraries can also use models just like controllers. Here is a very basic custom library called Sidebar. It depends on a model (sidebar_model) that will not be shown. The purpose of the Sidebar library is to return the variables need by the sidebar_view file.
File: application/libraries/Sidebar.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Sidebar
{
protected $CI; // Read the documentation link to see why this is needed.
public function __construct()
{
$this->CI = & get_instance();
$this->CI->load->database(); //only needed if not already done
$this->CI->load->model('sidebar_model');
}
public function get_sidebar_data()
{
return $this->CI->sidebar_model->get_sidebar();
}
}
The library method get_sidebar_data() returns the variables for the view.
Here is a controller that uses the custom library. It will use the custom library and a view file (not shown) containing HTML for the sidebar.
File: application/controllers/Main.php
class Main extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->library('sidebar'); //can also be autoloaded
}
public function index()
{
$data['sidebar'] = $this->sidebar->get_sidebar();
$this->load
->view('banner')
->view('sidebar_view', $data)
->view('main_view')
->view('footer_view');
}
}
Any other controller that needs to show the sidebar would use this same pattern.
This controller loads four different view files and is using "method chaining" which is encouraged. Method chaining executes a tiny bit faster. But the best reason for using it? Less typing.
The method chaning could also be type like this:
$this->load->view('banner')->view('sidebar_view', $data)->view('main_view')->view('footer_view');
But, IMO, putting each ->view() on a separate line makes it easier to read.
You can create a helper for your common tasks. Then create a function for your sidebar and call it where you need it. Check this link for more details about creating helper
You can also create a library for it. Although it will not a very good choice.
create sidebar (view page) and Call model directly inside that sidebar (view page).
secondly call sidebar (view page) directly inside all other view pages.

How do you create a custom page in Presta Shop?

I have followed many tutorials, but they are either cryptic or they did not work, or they wanted you to use the terrible CMS block module which gives you limited control over the custom elements of a page.
So far:
I created a controller called ProgramsController.php and put it into ps_root/controllers/front
class ProgramsControllerCore extends FrontController
{
public $php_self = 'programs';
public function init()
{
parent::init();
}
public function initContent()
{
parent::initContent();
$this->setTemplate(_PS_THEME_DIR_.'programs.tpl');
}
}
I created a template called programs.tpl and put it into ps_root/themes/mytheme/ folder
I then use: localhost/index.php?controller=programs or I use the SEO and links builder to create a localhost/programs link, and I get an error: Fatal error: Class 'ProgramsController' not found in ...\classes\controller\Controller.php on line 135
But that's not right since the path ought to be a ../controllers/front path, why is it looking in ../classes/controller? I assume from all the tutorials that the dispatcher should know to hook my front controller to the correct template. Why is this not working?
Basic Question:
In PrestaShop 1.6 I just want to know how to create custom pages like: http://myshop.com/mycustompage
But that it also utilizes the existing header and footer.
For creating a new custom page you have to follow some steps:
you have to create a new folder in your modules folder of prestashop like
C:\wamp\www\prestashop\modules\your_module_name
Then you put your controller file in your module folder like:
C:\wamp\www\prestashop\modules\your_module_name\controller\front\your_file.php
And in that you code like:
class ProgramsControllerCore extends FrontController
{
public $php_self = 'programs';
public function init()
{
parent::init();
}
public function initContent()
{
parent::initContent();
$this->setTemplate(_PS_THEME_DIR_.'programs.tpl');
}
}
Then you make a new folder views in your module like:
C:\wamp\www\prestashop\modules\your_module_name\views
Then in that you make another folder named template and in that another a folder named front like:
C:\wamp\www\prestashop\modules\your_module_name\views\templates
C:\wamp\www\prestashop\modules\your_module_name\views\templates\front
Then in that file you have to put your theme file Like
C:\wamp\www\prestashop\modules\your_module_name\views\templates\front\programs.tpl
and now render your file. I hope it would work.

Zend Framework View Helper not available in module when using layout

I'm starting to work with zend framework 1.12 and I ran into a little problem which I don't seem to be able to fix.
Up untill now i've done everything in the application, but now I want to build a module that handles all stuff that is related to settings.
Therefor i've created a new module and added a controller into it. This module automatically takes the layout from the application, which is what I want.
In this layout I use a view helper which works when I load a controller/action that is in the application folder. But when I try to load the layout around my controller inside my module the view helper is not available.
I hope I'm making sense and I would appreciate your help on this one!
Cheers!
If I understand you correctly you need to setup your view helper path in the bootstrap or application.ini, I do it in bootstrap:
protected function _initView()
{
//Initialize view
$view = new Zend_View();
//add custom view helper path
$view->addHelperPath('/../library/Namespace/View/Helper');
//do more stuff if needed
//add it to the view renderer
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
'ViewRenderer');
$viewRenderer->setView($view);
//Return it, so that it can be stored by the bootstrap
return $view;
}
also make sure your module includes it's own bootstrap file, this makes it possible to load resources to the module:
//at /application/modules/module/bootstrap.php
class Module_Bootstrap extends Zend_Application_Module_Bootstrap
{
//just an empty class is enough
}
hope this helps

Zend Framework loading views without re-loading the layout template

I need to load a profile layout and then have all of the profile views load into that layout without re-loading the layout, so that I can cache a big json object in the clients browser, to allow for data to be available on subsequent views, without having to do a new HTTP request for every view in my profile controller.
Is it possible to load the layout template and then load views into it, by disabling their layout template, so that the layout template never re-loads, only the view within?
Another option would be to have an iframe inside of a layout and then load the views into the iframe, by disabling their layouts, so that just the view is rendered.
Just need to know if this is possible and what the best option would be.
Thanks in advance :)
In the views where you do not want a layout try:
$this->_helper->layout->disableLayout();
This should prevent the layout from being shown.
If, for some reason, you want the same action from the same controller called many times but load the layout once (must be a better way to organise yourself) but you could always try:
public function indexAction()
{
static $firstTime = true;
if($firstTime){
$firstTime = false;
} else {
$this->_helper->layout->disableLayout(); //disable layout
}
}
I'll try to give a better example:
Lets say you have a controller foo with 3 views: index, contact, news.
class Foo_Controller extends Zend_Controller
{
//...
public function indexAction()
{
//normal view layout loads
}
public function contactAction()
{
//normal view layout loads
}
public function newsAction()
{
//no layout for this
$this->_helper->layout->disableLayout(); //disable layout
}
}
So the views that need a layout have one. The ones that do not do not. Unless you are saying layout but really thinking of something else then Zend_View_Helpers_Layout you will have t post some code to help us help you!

Categories