Using CakePHP 1.3 but have no database - cakephp

What's a good why to use CakePHP 1.3 for my website, but I have no database, since the site is pretty static?

You can use simple HTML to develop a site which is having all Static Content. And if it having a single contct page or something which you can develop in simple PHP. You don't need to use CakePHP for that.
CakePHP framework is used for web application that needs to interact more with databases.

Although I generally agree with gvLearner's point if you'd like to have a static html site, but still use some of CakePHP's abilities and be able to easily transform the site to a dynamic one in the future you can use Cake's built in Pages Controller.
The CakePHP core ships with a default controller called the Pages Controller that is generally used to serve static pages. Check out the documentation link I sent, I hope it'd would do you good.
Cheers,
Borislav.

Related

AngularJS with JSP

I am new to AngularJS.I have two questions.
Is it possible to use JSP pages instead of HTML in AngularJS.
Is it possible to create a web application using AngularJS without webservices (for fetching data from DB) and use HTTP servlet for that purpose
Is it possible to use JSP pages instead of HTML in AngularJS.
Even if you use JSP the final output will be HTML so you can use JSP in AngularJS but JSP files are mainly used to render the frontend with data that you can do using HTML only in AngularJS.
Is it possible to create a web application using AngularJS without web services (for fetching data from DB) and use HTTP servlet for that purpose
Whether you use plain Servlet or any framework that creates REST APIs, it will be HTTP calls only.
(This is a newbie question which applies equally to all front-end MVVM frameworks. I'll answer it for the general good.)
AngularJS is a front-end framework which runs in the browser. It relies on a server delivering the content (HTML templates, CSS and JS sources) to the browser.
What you use as a server, is entirely up to you. It depends on whether you need server-side dynamic content.
If none is required in that area, you can use a static HTTP server like LightHTTP, or plain old apache, or nginx, or anything else to deliver the AngularJS site to the browser.
But in most you will have some server interaction (i.e. storing / querying stuff in a database, or communication / synchronization with other users, etc). The common approach for that is to deliver HTML/CSS/JS statically and add a bunch of REST interfaces. Flask and Tornado are popular server choices for that, or stuff like spray.IO / akka.http for higher traffic volumes.
In specific cases, you may want to work with pre-rendered HTML templates (usually because you want to dynamically exclude parts of pages for security/user role reasons). Then you need a server-side framework with template rendering. Django, JSP, ASP, pick your favourite.
It seems like you are asking how to use AngularJs in a JavaEE application. And yes it is possible. Only your index.jsp will be in jsp, and all you other views will be in html.
You can then use http requests to fetch data through your servlets.
it can be useful. here are scenarios:
you want to save ram, cpu for mobile phones or machines that doesn't have lots of power. you can partially render page in jsp and keep only minimal in angular.
your team is traditionally jsp heavy and you want to use them and gradually transfer to angular. eg... for i18n rendering jsp seems far better. note that i18n may not add lots of values in angular and you may not want to throw up existing code in jsp.
I have been noticing strong views in stackoverflow and they seem to dismiss everything that doesn't fit in their utopian all new cutting edge. all the angular projects I worked had heavy dose of legacy pages using jsp and it doesn't make sense to rewrite everything from scratch or lay off whole team and start hiring from scratch. and thus, yes, jsp makes sense with angular.

Asp.Net MVC and AngularJS in same View

I´d like to know if exists a better way to render a view like this:
For the first load I need bring data from Controller like usual but after apply a filter in same page I need to start use AngularJS and never more uses Razor.
Is there a way to do that ?
Thanks for all.
Yes. you can do that.
Basically, you'd need to add the line below in your view. After you do that, the json is going to be available to the DOM / javascript and angular can take it from there. Hope this help
var json = '#Html.Raw(Model.MyJsonStringForMyCoolAngularJsApp)';
There are multiple ways to implement ASP.Net MVC with AngularJs.
I personally like Mini SPA (Silos). You can watch Miguel A Castro's video here.
You can also download the source at his website.
What it does is when a request comes in, it goes to ASP.Net MVC Route first. Then, Angular Route takes over the rest. It is a very slick design.
FYI: I also use Angular.Net Helpers to generate strongly typed views.
You could use WebAPI project in visual studio to exchange data between frontend and backend. It would go stateless, so to secure the data, you could use a mechanism like JWT.
The frontend would exchange JSONS from/to the backend using REST apis.
Yes. You can make angular views and exchange data using $http.get(/controller/method/). You can also configure routing using ngRoute.

Should I use Servlet for Database access and Display results in JSP using JSTL?

I've been learning Java for more than 6 months. I'm developing a web app and learning through building it. I'm using Glassfish Server and MySql. No frameworks. Using Servlet, JSP and EJB.
Now I'm querying database through JSP page and displaying results. Is this the best way? or Should I use servlet for querying database and displaying results in JSP?
I want to display only part of the resultset object and show the remaining if the user wants to see it. So Could I implement this using jsp alone?
I would recommend usind your Servlet to handle the database-connunication only and perhaps some logging on the usage of the Connection. The logic would best be implemented in JSP alone since you can better maintenance it.
Querying database through JSP page is not the best way. And because you are not using any framework is definitely not the best way to learn. While learning you need to try as much frameworks as possible to find out which one you can use or not to use. You are also need to learn patterns for building Java EE applications.
Should I use servlet for querying database and displaying results in jsp?
This approach is much better, but is not enough because of coupling database code with servlet code.
I want to display only part of the resultset object and show the remaining if the user wants to see it. So Could I implement this using jsp alone?
What do you want to display should be coded in the servlet.
You should avoid coding your business logic codes in your JSPs. Segrate your application into multiple layers, take a look at MVC design pattern.
Model: These are plain POJO classes where your DB transaction and business logic happens.
Controller: This is where your servlets goes. These classes accept user request, call appropriate Model classes and send response to view.
View: This is you JSPs, displays data to users. Avoid using Scriptlets in your Jsps. Use JSTL and EL.
Take a quick look at this example MVC application, and do your own searching on MVC. Hope it helps you to get started.

Loading Facelets templates from database

In my application (CMS for internal purposes) I'm facing the problem how to serve pages stored in the database with dynamic URL (e.g. http://example.com/page3) using the JSF. Generally, let's say I want to grab the page content from the database, put it inside jsf file and serve it as /page3. Is there any way how to obtain the request URL from JSF, search the database for the article (instead of searching *xhtml in the WAR), build dynamically the JSF XHML file and return it to JSF as InputStream for example? I've found this answed by Thomas Maerz, but it failed with
Unable to create a new instance of 'com.test.CustomResourceResolver': java.lang.InstantiationException: com.test.CustomResourceResolver
on my glassfish v4 (Mojarra 2.2), and I also found that ResourceResolver is deprecated in JSF2.2.
I've googled a lot, but this seems to be not very common/documented part of JSF.
Thank you for any help.
I did not understand fully the problem, but for url change you can use prettyfaces, for dynamic forms you can use primefaces ext and I am not suggest keep form in the database, if I know your target I can suggest more useful answer.

Best way to implement admin panel in CakePHP

I am trying to move from CodeIgniter to CakePHP and can't figure out the best way to implement an admin panel. In CI I would create two different applications, one for the frontend and one for the admin panel.
After Googling around, I have found three ways to implement admin panel in CakePHP:
Routing - I don't want to use this as I want by Controllers/Models to be separate for frontend and admin panel
Plugin
Two separate apps
Should I use plugin to implement admin panel or should I have separate apps? Any benefits of one over the other?
I normally develop the admin/backend as a plugin. This keeps your backend/admin controllers/views/models separated from the frontend and you don't have to jump through hoops to have separate stylesheets, layouts etc.
Another advantage is that both front- and backend are still part of the same application, so if desired, you can share logic/components, for example you'll be able to put helpers that are usable both for front- and backend in another plugin (e.g. plugins/Shared or plugins/Handytexttools) and use those both wherever you want
As a rule of thumb; put components that may be reuseable for other projects in a separate plugin, this way you can just add those plugins to other projects without problems. Keep your plugins simple; it's no problem to create a plugin containing just one or two helpers or models and a few files of JavaScript. This will make it easier to 'cherry pick' the plugins that you need for a project. Once Cake has 'cached' the file-locations of all classes in your plugins, the overhead of separate plugins should be minimal.
Coming back to the 'admin' plugin. Try to only include code specific for this project in your admin plugin and reusable parts in another one (e.g. Generic stylesheets and layouts for admin-panels). You'll be able to start a admin-plugin for your next project with minimal coding
Good luck with your project and enjoy CakePHP
If you want to keep your controllers and models separate - I'd go with a separate app, although you'll end up with a bunch of duplicate code between the apps (maintenance headache waiting to happen).
My choice would be admin routing and an admin theme.
Enable admin routing in /app/Config/core.php
In AppController beforeFilter():
$this->theme = isset($this->params['admin']) ? "Admin" : "Site";
Move all your site views and assets into /app/View/Themed/Site/
Create your admin themes in /app/View/Themed/Admin
Old and refers to CakePHP 1.3, but still is a question you should check: CakePHP admin panel
The Cake way is routing. I'd go with a plugin like CakeDC Users that makes things easier.
You could use admin-routing. Check out:
http://book.cakephp.org/2.0/en/development/routing.html#prefix-routing
Another solution -which I find really easy to implement- is like this:
In your AppController:
public function beforeFilter(){
$this->set('current_user', $this->Auth->user());
}
This makes the $current_user available in your app.
Then in your view-files, you can check:
<?php if ($current_user['role'] == 'admin'){/*place code for admin users to see here*/} ?>
<?php if ($current_user){/*place code for logged-in users to see here*/} ?>
I know this is an old thread. But would like to ask if anyone had trouble implementing the admin panel as a plugin. Particularly duplication of code.
For example you're implementing an e-commerce site. You have an OrderController both in the main and admin plugin. Don't you think it's kinda hard to maintain the logic in two places?
How about just using one main controller. It's serves two purpose. One as an API then the controller for your Admin webapp.
Your public side would then basically communicate via API to fetch data.
Do you think it's a good idea?
You can use admin views like admin_index.ctp just change this
//Configure::write('Routing.admin', 'admin');
to
Configure::write('Routing.admin', 'admin');
in core.php and in the controller add admin_index() function

Resources