Is there a way, to (automatically) generate, or "duplicate", the site tree for a translation into another language? For example via an url command or something like that.
Best regards,
Benedikt
you probably already found a solution by now ... but for future reference, SilverStripe user drx has created a batch action for translations as discussed here: http://silverstripe.org/customising-the-cms/show/7318
Tip:
->createTranslation() only creates a live-record even if you call this on a stage-object created with:
$a = Versioned::get_one_by_stage($this->ClassName, 'Stage', $this->ClassName.".ID = ".$this->ID);
To create Stage and Live-Pages you have to:
$translation_GB = $this->createTranslation('en_GB');
$translation_GB->doRestoreToStage();
Saving is done automatically in both cases.
You wouldn't duplicate the site tree to create a translation. SilverStripe supports multi-lingual sites. You can read up on it here: http://doc.silverstripe.org/sapphire/en/topics/translation
If you're wanting a way to automate this there's no native support but it wouldn't be hard to do. By URL would just be a matter of adding a function to your Page_Controller or, even better, you could write a simple module if it's something you're going to be doing regularly (just look at the googlesitemaps module for an example as it loops through pages as you'd need to). You can get all pages by calling:
Versioned::get_by_stage('SiteTree', 'Live', $filter);
Then you'd create your translation(s) as you looped through. You could also do this via commandline by using SilverStripe's CMDline utility "sake": http://doc.silverstripe.org/sapphire/en/topics/commandline
Related
Really not sure if the title of the question suits the question overall. But here goes.
What I have currently is an existing SaaS project. That we want to roll out a new template over time. Think of how google introduces new features. Or some other sites might with "Try our new Beta Version".. type of thing. Well we want to do the same, and then we will eventually phase out the old look and feel.
With that, this application is built on top of Zend Framework, so looking through docs I can figure out how to override the template on a given controller. But what I want to basically do, is likely going to make use of the sessions. If it exists, use this template. If not, use the old one.
Is it possible to override the default template in such a fashion? Right now for example, the default loaded file, is "tops.phtml" if the session exists I'd like to load "tops_v2.phtml" for example. So it can use that as the template instead of "tops.phtml" when the session is found.
Zend Framework 1.x solution:
You can disable ViewRenderer plugin in the action, and choose template manually:
public function indexAction(){
$this->_helper->viewRenderer->setNoRender(true);
echo $this->view->render("path/to/template/template.phtml");
}
I think that layouts are the thing you probably want to use, as was briefly touched on by Richie. Based on the question, I'm guessing you aren't already using them. Ultimately you can design a layout that defines the overall website look and then each of your action templates will only then render a fragment of the page (which will be dynamically placed in the content portion of the layout).
Using whatever logic you choose, you can then assign one of any number of layouts to be used on a given page load and of course you could store this as a user preference or something.
I have been asked to do a project where the client can create PHP plugins and add them to the website… same concept as WordPress plugins.
What is the best way to make a software that supports that? I'm not asking for the solution, I'm asking for the concept or structure.
First of all, you have to determine how do you want your plugins integrated. If you want something like Wordpress plugins, which are just plain functions most of the times, then it's extremely easy. It's like adding new code to your application.
Well, basically, your application should be able to build a list of plugins available, and to determine which ones are enabled. The list can be built by browsing the files, a config file, or whatever. Enabled plugins can be stored in the database for example.
Then, you just do an interface where the user can enable each available plugin. When enabling it, the web application would write information about it in the plugins database, specifying that it's enabled. Then, the application calls a specific method of the plugin class (really, OOP is mandatory in correct plugin development), like Install(). To avoid exceptions when plugins have no such method, all plugin classes should inherit a base class written in the main web application, which does contain a definition for that method. That method has the sole purpose to perform the initialization of the plugin (create tables to the database, populate statistics, etc).
Also, at each request, your web application should include all the files of the plugins that are specified as enabled. Then use them however you want. Call their methods from templates for example. If you want to write plugins that are transparent to the template developer, then you could do just like in wordpress. There, the plugin at initialization (for example when it's file is included) writes specific data into arrays of actions. It can write what function should be called, with what parameters, and when to be called.
You can even make something like event triggers in your main web application, to enable customization. Before drawing something, call a function called something like do_action("before_output_of_something"), and after output is ended, call the function do_action("after_output_of_something"). The string parameter would be a key in an array of triggers, that points to an array of actions (event handlers). To add event handlers call a function like this add_action("before_output_of_something", $object, "method_name", array("parameters")). do_action method passes the array of actions, and uses call_user_func() PHP function to call event handlers.
There is much more to this topic. All depends on what exactly you want to make.
What I wrote here is just a lousy attempt to express some of the possibilities. What you should do is find a good book, maybe about just this topic.
I would solve this by using the event-dispatcher pattern. You define certain points (events) in your main application. Plugins can register for this events and will be executed, when the related event is triggered.
There are multiple options. Most common is the hooks concept with simple plugin functions, where you just have to include() a plugin from a central configuration script. Each plugin has to register itself, so usually there is a plugin registration method. But it can also just look like this:
$app_plugin["add_title"][] = "do_whatever";
function do_whatever($request, &$page) {...}
And in your main application you just define a couple of plugin calls, wherever you see the need for it. You would use a wrapper function to invoke all plugins, but basically you look for the hook name and invoke all registered plugins:
foreach ($app_plugin["add_title"] as $func) {
$output .= $func($_REQUEST, $page);
Each named hook can have a different set of parameters. Typically you would want to get additional content, but sometimes plugins just modify existing variables, or influence the application flow.
The more hooks you have, the more diverse extensions are possible. And it's not necessary to use functions only. Of course this scheme also works with objects (they just need to be instantiated first.)
I want that cms\framework to create me tables like "Users" "Cameras" and so on and declare classes and simple default methods for them (like paged sql relults and so on).
I mean I say to it: I want Users to have ID, SpecialNumber and Name Flilds.
and I want to get from it class for table generation (to call it once) and class containing methods such as Search by ID, SpecialNumber and Name, Create User, Delit User and so on functions.
Is there any framework/cms like this for working with CODE not ui's and so on... so to say PHP generator or something...
The result should be as that framework free as possible.
So Is there any free, open source php CMS\framework for described case?
Cake PHP is a framework that takes the code generation approach, corresponds to your description, and is pretty mature.
I personally dont find code generation (scaffolding) that much of a deal, you end up rewriting it anyway, I would use Zend Framework and code my stuff, or write my own codegen commands if it's important for the project.
You might wish to consider SilverStripe which takes subclasses of SiteTree (if I recall correctly) and creates tables and an administrative interface for them.
I was looking on many template libraries, som I have fair mess in general idea what is out there ready to download/use and what I want to use, so maybe you could help me with this.
I'm currently learning CodeIgniter, thinking about moving to Kohana later. I would like to include controllers/modules(/module function maybe?) based on needs of template/site.
Example, so you would understand:
I have xml-defined page saved in mysql, which states, that in
<div id="sidebar">, i want to use news panel/widget - something like:
<div id="sidebar">{widget:news;3;60}</div>.
I'm looking for template parser and/or way to do it, so in main application I load page, then template. then I look up what modules/widgets page/template use and load them dynamically, pass them parameters (in example news;3;60 - module news, 3 last, 60 characters limit each), and echo their result in place of where i called them.
The usage for this should be understandable - if I use news module on 27 pages, just somewhere with last 3 news, somewhere last month, etc., i want to include it simply and edit it on one place.
Other problems in my mind are: I'm thinking that it would be best to have all modules at one time (not load them one there, one here), so I can access database on one place, etc.
I'm kind of lost and maybe someone will have some idea for me :)
The two best ways to do this are:
Use my CodeIgniter Dwoo implementation and build plugins
Use wiredesignz' Widget plugin
You could of course use Smarty plugins but yuck, who still uses Smarty?
Remember when creating Dwoo plugins that the CodeIgniter instance is available to any PHP loaded in on that request, so wether its Dwoo plugins, modifiers, blocks, etc you can always use:
$CI =& get_instance();
$CI->load->model('something');
//etc
If you're using Kohana3, you could use the HMVC-capabilities. A quick way would be to create a helper-class that you can use in your views. In your view you then make a call to this helper. This helper would start a new request that would trigger the correct controller/action.
There is some kind of widget-class in the Kohana-forums, but that requires a class for the widget instead of utilizing the (already existing?) controllers via the HMVC-capabilities of Kohana3.
I am trying to use the MVC architecture of sugarcrm to add a new action and with that a new view.
I have managed to create a controller with the action and also a class view, the only thing I can't figure out is how to create a simple html page.
Do I really have to use the metada way of sugarcrm?? I just want a simple form with two or three fields.
Are there alternatives to the metadata or do I really have to use it to create my simple page????
You will want to stay within the metadata framework to create your new page if possible. However, once you are in the view controllers, you can echo out anything you wish and still stay "upgrade safe" by overriding the display() function. But, the right way to do what you are wanting to accomplish above is to not only override the display() function but also create a new tpl file (custom/modules//tpls/view.tpl) and then perform whatever you need to perform PHP wise and then assign the variables via the smarty templating engine (I know this sounds complicated - but it's not. It's actually pretty straightforward once you understand Smarty).
One other thing - make sure you are doing all of this (including your controllers and view files) in the custom/modules directory. As this will also keep things upgrade safe. And keep you free from all kinds of headaches in the future. :)
Here is a link to the SugarCRM Developer's Guide online and also a link to their Developer's website. SugarCRM has a pretty good community of developers on the forums so feel free to ask questions there as well.
Developer's Guide:
http://developers.sugarcrm.com/docs/OS/5.2/-docs-Developer_Guides-Developer_Guide_5.2-toc.html
Developer's Site:
http://developers.sugarcrm.com/
Hope this all helps!
Try to do following:
create a new module
put your page into custom/modules/
using URL index.php?module=&action= (without php extension, of course) you can access to your page.
If you'd like to have different action name and page name then you should add the file action_file_map.php
into your module directory and specify inside the mapping:
$action_file_map['action_name'] = 'path_to_your_page';
Note that action_name must be all lowercase - the SugarController won't be able to to match mixed-case actions (true as of SugarCRM 6.1.2).