I am very new to cakePHP but I am a bit knowledgeable with Ruby on Rails. I tried creating a controller using the cake bake command in the console but it said:
Your database does not have any tables
As far as I can remember in rails, it allowed me to create controllers without tables or even without setting up database. What I am trying to do is that I want to create a controller and a view for pages such as Home, About, and Help. I don't think those pages still need a model or a database table. Pls help.
sure you can create controllers and views... even models without tables.
But you can't bake them =D bake is just to read the database and help you create your classes from there. So if you dont have any table, you dont have anything to bake..
For the static pages such as Home, About and Help you could use the PagesController
Cheers!
Related
I am trying with the help of Entity Framework to set up this without having to deal with the code-related part of SQL.
I created a model and added a migration via package manager console and it all worked well it updated and created the table.
The thing I want to ask is how does the entity know which migration I want to add.
I used:
add-migration (and put here the name of the migration file)
But the thing I don't understand is how does it know which model I want for my table?
Or put it in other words if I would have 2 models before I did any migrations which model would get chosen?
Would really appreciate it if someone could help me out.
Thanks in advance
Seems you are using entity framework migrations and got confused how it works. Here is the explanations:
Question: But the thing I don't understand how does it know which model I want for my table?
If you look into your project folder there is the directory
Migrations. Inside it all the migrations history logs written
into.When we made any changes on data model, EF Core compares the current model against a snapshot of the old model to determine the
differences, and generates migration source files; the files can be
tracked in your project's source control like any other source file.
Once a new migration has been generated, it can be applied to a database in various ways. EF Core records all applied migrations in a
special history table, allowing it to know which migrations have been
applied and which haven't
Question: If I would have 2 models before I did any migrations which model would get chosen?
As said earlier, as it keep track previous migrations history, so in your old model it compares the differences and overrite latest
changes that were not written on older files. This is how it works.
Hope above explanations guided you accordingly and redeem your confusions. You can also have a look on official documents here
Does anyone knows how to create a view in database with CakePHP3?
Is there a way to do this with migrations?
Like define a view to being executed then when I run cake/bin migrations migrate this create view in BD. Than this may create a view and I must be able to execute this view whatever I want in models or controllers?
Thanks for your help in advance
As markstory said in this issues on GitHub this, functionalities didn't exist ye and may be released soon:
https://github.com/cakephp/cakephp/issues/11632
https://github.com/cakephp/migrations/issues/347
I am looking for a way to map existing tables in a project with the Eloquent ORM and use them in code. I use a MySQL database and plan to migrate to MSSQL. Any way points are appreciated.
You'll have to do this manually.
i.e., create an eloquent model for each of the tables you want access to in your code using eloquent.
If you don't have timestamps named created_at and updated_at, in your model you can disable those columns.
Manually
If you have a users table you could 'map' it with a user.php file in your models folder like this
class User extends Eloquent {
protected $table = 'users';
public $timestamps = false;
}
Via artisan
You can use Jeffrey Ways Laravel Generators to help streamline the initial creation of your models, however you'll still need to make the timestamp modification manually.
This looks like an old post, but it was edited a couple of days ago, so I don't know if the original author is looking for a solution again, but if someone needs this info, here is a packagist package for Laravel 5 to do what you are asking.
Laravel 5 model generator from existing schema:
https://packagist.org/packages/ignasbernotas/laravel-model-generator
Hope that helps someone!
There is also a Eloquent Model Generator library. It can be used for generating Eloquent models using database tables as a source. Generated model will include relation methods, docblocks for magic field and relations and several additional properties.
Another here: https://github.com/Xethron/migrations-generator.
You'll only want to use these generators for local development, so you don't want to update the production providers array in config/app.php. Instead, add the provider in app/Providers/AppServiceProvider.php.
For more details look here - https://packagist.org/packages/ignasbernotas/laravel-model-generator#user-content-installation
You can also use SQL Server Migration Assistant (SSMA) to port the database to SQL Server, but you will still need to write your own models to match the schema.
http://blogs.msdn.com/b/ssma/
http://www.microsoft.com/en-us/download/details.aspx?id=43688
Still this might help get halfway there, from both sides of the puzzle.
I am now building my first joomla component.
I have 3 tables in it:
__questions
__resaults
__display
I also need the Joomla user table:
__users
I have a single view:
view.questions.html
this view gets data and also needs some database functions. It needs to:
Get information from the user table.
Get information from the resaults table
Get information from the display table
-SET- information to the reaults table
Now, I know Joomla is built with MVC architecture. This, I assume, means no dealing with database in views.
Where should I store the database hendling functions, and how can I call them in the front end?
The function dealing with questions is in the question view model, no problem, but what about the other tables? Should I put the functions dealing with them in the question model as well, the helper file, or make models for each other table, and call them from the question view? If i should make other models, how do I call them from the question view?
Thank you very much for your help!
Create a model for each table.
You will then instantiate them from the controller to make them available to the views.
You can save a lot of time and also learn a lot by using the Component Creator: http://www.notwebdesign.com/joomla-component-creator/ It will do all the MVC stuff for you.
I am building a site that needs to display some product info from a Magento Database, but display it on another page/site outside the Magento intallation. I know the information gets displayed twice, but I would like the site to avoid content duplication and pull that same info from an only source, the Magento product database.
Is this posible? Has anyone done it?
What would be a lot easier to do would be to pull in the entire Magento engine into your external page. This [unlike the rest of Magento] is pretty easy to do.
All you have to do is the following:
// Load Up Magento Core
define('MAGENTO', realpath('/var/www/magento/'));
require_once(MAGENTO . '/app/Mage.php');
$app = Mage::app();
Now you can use any of the Magento objects/classes as if you were inside of Magento and get your attributes
$product = Mage::getModel('catalog/product')->load(1234);
$product->getSku();
$product->getYourCustomAttribute();
etc etc.
Yes, I've done it a few ways. The safest way to do this is using the webservices Magento exposes to query objects programmatically. This will insulate you from database-level changes (such as the flat product catalog, a recent addition).
Failing that (if the performance of the webservices doesn't meet your needs), you can reconstruct the catalog data from the database directly. Use the following tables (assuming you're not using the flat catalog):
eav_entity_type
eav_attribute
catalog_product_entity
catalog_product_entity_int
catalog_product_entity_varchar
catalog_product_entity_text
catalog_product_entity_decimal
catalog_product_entity_datetime
You'll want to read up on EAV models before you attempt this. Bear in mind that this is largely the topic over which people call Magento complicated.
Hope that helps!
Thanks,
Joe