Jump to content

Search the Community

Showing results for tags 'MVC'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to ProcessWire
    • News & Announcements
    • Showcase
    • Wishlist & Roadmap
  • Community Support
    • Getting Started
    • Tutorials
    • FAQs
    • General Support
    • API & Templates
    • Modules/Plugins
    • Themes and Profiles
    • Multi-Language Support
    • Security
    • Jobs
  • Off Topic
    • Pub
    • Dev Talk

Product Groups

  • Form Builder
  • ProFields
  • ProCache
  • ProMailer
  • Login Register Pro
  • ProDrafts
  • ListerPro
  • ProDevTools
  • Likes
  • Custom Development

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

Found 8 results

  1. I saw in the 'template structure methods' in the doc section that ryan mentioned a mvc method for beginners. When will it be published? https://processwire.com/docs/tutorials/how-to-structure-your-template-files/page5 I'm just curious
  2. Just found an article about templating and it really made me smile: Your templating engine sucks and everything you have ever written is spaghetti code (yes, you) I guess many people here on PW don't give much attention to templating engines as PW runns smooth even whithout one. But the concept of DOM Templating really looked interesting to me. I really would like to hear your opinions!
  3. Hi, I'm developing mailbox and I wanna rather use single class then making pages. Here is the plan (or I think that its a good plan): - I have mailbox.php template and mailbox page - when user click on mailbox, on sidebar he have options to write/read massages to and from ppl Instead of making these pages, and to prevent "ugly URLs" I wanna offer user to call write msg like: http://www.domain.com/mailbox/?actionType=newMail. Also, I think that this will be useful for some other stuff which I wanna add to my project. I'm not skilful but wanna learn stuff. Cheers
  4. This might sound like i'm stupid, but bare in mind i'm 80% front end dev. Now I know PW works on hooks, but is it possible to use MVC structure when building plugins?? In a way i'm just curious as to the general architecture of PW and what's possible. ( in the sense of can i grab some MVC built functionality elsewhere and plug it into ProcessWire? ) Any help getting my head around this would be great
  5. Hi altogether, since I am currently working on a project that has (hopefully) the potential to reach a certain level of complexity at some point, I wanted to start the template structure in a scalable and "proper" way. In the following I'll try to give a summary about the approach I'm testing: 1. Directory structure inside site/templates/ /controllers/ /views/ 2. Create init file named... site/templates/init.php...containing (for example): <?php function getPartial($name, $allpages) { // Site wide $settings = $allpages->get('/meta/settings'); $root = $allpages->get('/'); // User related $loggedInUser = wire('user')->isLoggedin(); // Page related $title = wire('page')->title; $children = wire('page')->children; $template = wire('page')->template; include($config->urls->templates . 'controllers/' . $name . '.php'); include($config->urls->templates . 'views/' . $name . '.php'); } 3. Uncommenting prepandTemplatefile in /site/config $config->prependTemplateFile = 'init.php'; 4. Creation of partial (controller and view) in their respective folders /site/templates/controllers/test-partial.php /site/templates/views/test-partial.php Example controller: <?php $homepagetitle = $root->title; Example view: <h1><?= $homepagetitle ?></h1> <p><?= $title ?></p> 5. Creation of layout file. I tried to put these in a folder called /layouts, but that does results in PW not finding new templates anymore in the PW Admin when creating a new templates. Any ideas? Changing index.php's $config->urls->templates ? Example layout: <html> <head> <title>Foo</title> </head> <body> <?php getPartial('test-partial', $pages); ?> </body> </html> So, for some reason I have to explicitly inject $pages or wire('pages') into getPartial() - but I have no idea why, since $page or wire('page') is working without problems in the functions scope. But: The output is just as intended. The title of the root page in a h1 headline, and the title of the page using this "layout" in a paragraph. Any feedback or pointing to pitfalls of this approach would be highly appreciated Best, marcus edit: Funny, essentially this is a very stripped down way of Template Data Providers, which needed Twig the last time I tried to use it.
  6. Hi I am looking into ProcessWire to build an application. I am used to building applications that have db models separated out, which is nice and organized for building the application. I would also want to separate out a lot of the logic for the application(more in a Model View/Presenter fashion) and have seen some people are doing MVC with ProcessWire. But I wonder if I use pages, would this be similar to having models? I read somewhere that Users are pages in processwire, and user attributes can be fields of these pages. So maybe pages are one of the magic ingredients in PW? Can/should I do the same for other db models in the application(use pages as the models), or would I better be served by integrating an MVCmodule into PW, or using Laravel with PW? It's starting to seem like PW is a very different type of framework and can do all the MVC stuff, but in a slightly different paradigm, and that Pages are like the model, and Templates are the View/Presenter/Controller. And you could separate out the controller if you wanted to create some classes and implement some routing if you wanted.
  7. Today i found a new, at least for me, kind of PHP-framework, which does look very promising. It may be a bit off topic for processwire, but for all programmers here that were using a framework like symfony or laravel, it could be a very interesting alternative. The project is called Phalcon and here is what they are saying about it: I have not used it myself, but not only the perfomance does look promising (from two to four times faster than every other PHP-framework), also the framework is feature-rich. It does not make assumptions about directory-structure. Have a look and tell me what you pros here think about it.
  8. Introduction Dear community. As some of you may know I've been busy creating a MVC Module for Processwire. I've finished quite a bit of it and I am now ready for a tutorial on a quick website to get you started! For this tutorial I am using a clean install of Processwire 2.3 and my Module 0.2.4 Get the module at Github http://github.com/hawiak/mvcmodule . Main focus of the module is to split logic from design without losing the flexibility of Processwire we all fell in love with. Alright lets get started. Installation Once you have the module downloaded we are going to install it, we need the MvcModule folder in the /site/modules folder. And we need the AppController in the /site/templates folder (You can find the AppController in the /site/templates folder) Once you've put the folder in there we are going to install the module, check for new modules and you'll see MvcModule Click on it and hit install to install the module. Once you've installed the module you'll see some configure settings and you'll notice a new tab on your admin. But click submit, dont forget this or all the paths WONT WORK! Setting up your home controller Ok we are ready to set up our first controller. To easily set up your template to enable MVC we are going to the MVC tab in your navbar. You'll notice a button saying " Create controller" Click on "Create controller" and for this tutorial we are going to use the home template, select the home and click "Create". If everything is correct you will see this: Now we are done in the process side of it and we'll get into the coding. Get your favourite code editor open and lets create our controller. Open the /site/templates/home.php file in your editor. Remove the code thats in there completely. And save it. For the module to work with the template file we need to create a class called HomeController and extend AppController. like so: <?php class HomeController extends AppController{ } Creating Views and layouts If you go to your websites homepage you'll see something along the lines of: Thats because by default you will need an Index method, a home method for your controller, so lets create one! <?php class HomeController extends AppController{ public function index(){ } } Lets try it again! Oops... Well it seems like we're missing a view, so lets create the view, we first need to create a folder with called Home (the same as the controller name but start with capital) And in that folder we'll create a file called index.tmpl Now of you run it you'll see that you are not quite done yet you'll see something like this: I promise after we create the layout we are done. So lets create a folder called layouts and a file called layout.php in there. Displaying data Now we're done with the setup and we can start coding, lets say you want to get the content fromt he field body on your page displayed? Well thats easy put this in your index method. $this->set('body', $this->page->body); What this does is that it sets a variable in the view we can use called body so all we need to do to display this is go to our view. And add {{body}} to the view. Now go and refresh your page! oh wait... nothing shows up...? Oh yes we use Twig template engine we need to add this to our layout.php {% block view %} {% endblock %} (Yes yes I know its complicated for just a simple task but trust me you'll love it later!) Refresh your page and check it out! You'll see that the text is displaying but the markup isn't really working, we need to use the |raw extension in order to make this work, so change the index.tmpl content to this {{ body|raw }} Use |raw for all the HTML markup, always. Styles, scripts and snippets Now this is quite boring, I know but lets start doing some interesting stuff, lets implement Bootstrap! go and download bootstrap at getbootstrap.com Once you've downloaded create a folder in /site/templates called "assets" the dist copy the bootstrap.min.css out of /dist/css to /site/templates/assets/styles and /dist/js/bootstrap.min.js to /site/templates/assets/scripts/ Now we want to use this, MvcModule has some great options for this! Change your HomeController to this <?php class HomeController extends AppController{ public $scripts = array( '1' => 'bootstrap.min.js'); public $styles = array( '1' => 'bootstrap.min.css'); public function index(){ $this->set('body', $this->page->body); } } Now go over to your layout and change the contents of your layout to this: <head> {{ this.render_headers()|raw }} </head> {% block view %} {% endblock %} You'll now see your style (If not try going to the MvcModule configure settings and remove the first / from /site/templates/assets) Now we forgot to include JQuery, so lets download jquery at jquery.com We need to put that in the /site/templates/assets/scripts And we need to put it in the array, you can just do that as follow: public $scripts = array( '2' => 'bootstrap.min.js', '1' => 'jquery.min.js'); The number in this array indecates the order on which the scripts will be loaded. Now you should see something like this! Now lets create a navbar with all the pages using the bootstrap navbar component. To do this we will create a snippet create a folder called snippets in /site/templates and a file called navbar.php Lets first create a variable with all the pages in the index method $this->set('menu', $this->pages->find('/')); Lets now create our snippet, lets just create this first in our snippet navbar.php <nav class="navbar navbar-default" role="navigation"> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <ul class="nav navbar-nav"> <li class="active"><a href="#">Link</a></li> </ul> </div> </nav> We need to tell the controller to use this snippet we do that by using an array. Change your controller to the following: <?php class HomeController extends AppController{ public $scripts = array( '2' => 'bootstrap.min.js', '1' => 'jquery.min.js'); public $styles = array( '1' => 'bootstrap.min.css'); public $snippets = array( 'navbar' => 'navbar.php'); public function index(){ $this->set('body', $this->page->body); $this->set('menu', $this->pages->find('/')); } } And change your layout to this: <head> {{ this.render_headers()|raw }} </head> {% block navbar %} {% endblock %} {% block view %} {% endblock %} You see that I created a block here and called in Navbar. The snippets content (that we assigned to navbar => file_name) will be put in this block! So lets now use our variables and the Twig template engine to the fullest! Change the navbar.php snippet to: <nav class="navbar navbar-default" role="navigation"> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <ul class="nav navbar-nav"> {% for item in menu %} <li class=""><a href="{{ item.url }}">{{ item.title }}</a></li> {% endfor %} </ul> </div> </nav> You see we use a for loop here and use the PageArray menu here and generate the menu here. You can use the variables in the view as well. Setting a title Lets set a title, this is fairly easy, lets define a variable in our controller that will be the same for every view in this controller public $title = "Home controller"; Now go to your layout.php and do add this to the head: <title>{%block title %}{% endblock %} {{ this.controller.title }}</title> Now as you can see we created a block, what this allows us to do is create the same block in the view like this: {% block title %}Index{% endblock %} And you will see that your title is "Index Home controller". This is because the title block replaced the title block in the layout file. Views Inside views you still have access to processwire objects and even to the MvcModule as you've seen with render_headers(). The view template used is Twig, check out more here http://twig.sensiolabs.org/doc/templates.html This is a basic setup for a website with MvcModule. I will extend this tutorial and update it whenever needed!
×
×
  • Create New...