Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About jiros1

  • Rank

Profile Information

  • Gender
    Not Telling
  1. Hi Ignace, thanks to your hint I've made the following changes and got it working: GameType: $builder ->add('name', TextType::class, [ 'attr' => [ 'class' => 'form-control', ], ]); $builder ->add('type', EntityType::class, [ 'class' => 'AppBundle:Type', 'choice_label' => function ($type) { return $type->getName(); }, 'multiple' => false, 'expanded' => false,
  2. Thanks for the reply, but by now I'm already using that. I've changed my code so I want to edit my original post, now I'm looking for the edit button... How silly is that I now have selectbox but it replaced my exisiting textfield, I think I know why that is, textfield holds the value for Game.name but the newly added selectbox holds the value of type.name. GameType.php public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add( 'name', EntityType::class, [ 'class' => 'AppBundle:Game',
  3. Hi! For a form I would like to render a selectbox with values from another relation: Type. This is a many-to-one relation, owned by Type. Type has many Games, while Game has one Type My question is, how do I show a selectbox with values from Type? e.g: Game: Monopoly Select Type: (selectbox) - Party game - Strategy - Co-op - etc. ----------------------------------------------- This is what I have: GameType.php <?php namespace AppBundle\Form; use AppBundle\Entity\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; u
  4. Thanks for your quick reply, Jacques1, it looks a lot better now thanks to you: const DB_HOST = 'yourhost'; const DB_USER = 'user'; const DB_PASSWORD = 'pswd'; const DB_NAME = 'db'; const DB_CHARSET = 'UTF8'; $dsn = 'mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset='.DB_CHARSET; $databaseConnection = new PDO($dsn, DB_USER, DB_PASSWORD, [ PDO::ATTR_EMULATE_PREPARES => false, // important: Disable emulated prepared statements: PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ]); class Model { protected
  5. I want to clean up my code by inheriting the database class so I can connect from any class that wants to inherit the database connection. I'm not sure this is the right way but I thought about fixing this by inheriting the __construct function, but how would I call it in this example? Currently I have this; it works, but could this be improved? Or is there a better, cleaner way to do this? $pdo = parent::__construct(); My code: class database { function __construct(){ $servername = "localhost"; $username = "root"; $password = ""; $dbnam
  6. Thanks a lot, I've got it working now! A question though, how come we can do a foreach iteration now? And why doesn't that work for MYSQLi?
  7. Hi, Thanks for taking the time. I'm trying PDO for the first time and I'm trying to make a CRUD codebase. I can insert but I have trouble with the select statement and iterate through the data, Apache gives me this error: Fatal error: Uncaught Error: Call to a member function fetch_assoc() on boolean in index.php:38 This is line 38: $getName = $result; while( $row = $getName->fetch_assoc() ){ echo $row['name']; } This is my code: $pdo = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); // set the PDO error mode to exception
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.